...
| Code Block |
|---|
import org.junit.Test
import static org.junit.Assert.assertEquals
class ArithmeticTest {
@Test
void additionIsWorking() {
assertEquals 4, 2+2
}
@Test(expected=ArithmeticException)
void divideByZero() {
println 1/0
}
}
|
Alternatively, one could use the shouldFail method as follows:
| Code Block |
|---|
class ArithmeticTest {
final shouldFail = new GroovyTestCase().&shouldFail
@Test
void divideByZero() {
shouldFail(ArithmeticException) {
println 1/0
}
}
}
|
Our test class includes two tests additionIsWorking and divideByZero. The second of these is expected to fail with an ArithmeticException exception.
...