I want to set an expected exception for a JUnit 4 test using Scala. I am current doing something similar to the following:
@Test(expected=classOf[NullPointerException])
def someTest() = {
// Some test code
}
But I get the following compiler error:
error: wrong number of arguments for constructor Test: ()org.junit.Test
This is looking forward a bit, but the syntax for annotations in 2.8 has changed to be the same as what you originally posted. The syntax Tristan posted is correct in the current stable version, but it gave me errors when I upgraded my project to a nightly 2.8 compiler. I'm guessing this is due to the inclusion of named and default arguments. There is also some discussion on the Scala mailing list. Quoting Lukas Rytz:
Also note that in 2.8.0 the syntax for java annotations will no longer use the name-value pairs but named arguments instead, i.e.
@ann{ val x = 1, val y = 2} ==> @ann(x = 1, y = 2)
The way scala deals with attributes is a little funky. I think what you're trying to do should be expressed like this:
@Test { val expected = classOf[ NullPointerException] }
def someTest {
// test code
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With