How to set an expected exception using Scala and JUnit 4

annotations, junit4, scala

Solution

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
}

- Scala language page with many annotation examples.

Problem

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 ```

Original source