Created
September 27, 2017 01:58
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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