Skip to content

Instantly share code, notes, and snippets.

@DaoWen
Created September 27, 2017 01:58
Show Gist options
  • Save DaoWen/8590930879f8be0e9c32618715f107ad to your computer and use it in GitHub Desktop.
Save DaoWen/8590930879f8be0e9c32618715f107ad to your computer and use it in GitHub Desktop.
Example of simple JUnit4 tests in Scala, including exception checking via @test(expected).
import org.junit.Assert._
import org.junit.Test
class ExampleTestSuite {
@Test
def ok() {
assertTrue(true)
}
@Test(expected = classOf[IllegalArgumentException])
def badRequire() {
require(false) // fails with an IllegalArgumentException
}
@Test(expected = classOf[AssertionError])
def badEnsuring() {
true ensuring (!_) // fails with an AssertionError
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment