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?

5
  • Can you clarify? You want to write unit tests for java code in scala? scalatest.org for example advertises that "you can test either Scala or Java code." Commented Dec 6, 2015 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? Commented Dec 6, 2015 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. Commented Dec 6, 2015 at 16:48
  • 1
    If you really want you can start with the compilation process from scala. Scala has it's own runtime version stackoverflow.com/questions/16162483/execute-external-command and you can access java's runtime as well daily-scala.blogspot.de/2009/08/calling-java-apis.html Commented Dec 6, 2015 at 17:13
  • @zapl This should be an answer. Commented Dec 6, 2015 at 18:22

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.