September 2015
Intermediate to advanced
250 pages
6h 40m
English
Using JUnit to run tests written in Scala is really simple. Since Scala compiles to Java bytecode, you can write your tests in Scala, use scalac to compile your code into bytecode, and then run your tests like you normally run JUnit test cases. Remember to include the Scala library in your classpath. Let’s look at an example of writing a JUnit test in Scala:
| UnitTesting/UsingJUnit.scala | |
| | import java.util.ArrayList |
| | import org.junit.Test |
| | import org.junit.Assert._ |
| | |
| | class UsingJUnit { |
| | @Test |
| | def listAdd() { |
| | val list = new ArrayList[String] |
| | list.add("Milk") |
| | list add "Sugar" |
| | assertEquals(2, list.size) |
| | } |
| | } |
We imported java.util.AraryList and then org.junit.Test. We also included all the methods of ...
Read now
Unlock full access