0

So im trying to test two java programs and if they have the same output, and I want to do this within scala. So how would i do this within scala, should i use the java runtime library or is there one in scala?

Alan Liang
  • 17
  • 3
  • Can you clarify? You want to write unit tests for java code in scala? http://www.scalatest.org/ for example advertises that "you can test either Scala or Java code." – zapl Dec 06 '15 at 15:29
  • @zapl what i want to do is, i have two .java files which i want to compile and execute from within my scala code, and check whether the outputs are the same. I know you can run a java program from another java program by using the runtime library to do terminal commands like javac etc, but im not sure if scala has one similar to that? if that all made sense? – Alan Liang Dec 06 '15 at 16:40
  • 1
    Scala runs in JVM and therefore and can use any of the java libraries. But I really don't see any reason to compile your java programs from Scala. – pedrofurla Dec 06 '15 at 16:48
  • 1
    If you really want you can start with the compilation process from scala. Scala has it's own runtime version http://stackoverflow.com/questions/16162483/execute-external-command and you can access java's runtime as well http://daily-scala.blogspot.de/2009/08/calling-java-apis.html – zapl Dec 06 '15 at 17:13
  • @zapl This should be an answer. – Alexey Romanov Dec 06 '15 at 18:22

1 Answers1

1

You can use the JavaCompiler API. Or, simpler, just run javac in an external process, as @zapl's comment says.

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487