-2

what's wrong with this. I have junit 4enter image description here

Wang-Zhao-Liu Q
  • 13,555
  • 29
  • 73
  • 112

2 Answers2

5

You can declare on the @Test annotation that, for the test to pass, it must throw these exceptions:

@Test(expected = NullPointerException.class)
public void testSynapseOne() {
    // test
}


@Test(expected = IllegalStateException.class)
public void testSynapseTwo() {
    // test
}

Of course, you have to be sure you're testing the right thing - currently, your tests don't make use of the constructor, which is the critical piece you want to test.

Oh - you don't want to have your tests extend TestCase unless you need compatibility with JUnit3.x.

Community
  • 1
  • 1
Makoto
  • 100,191
  • 27
  • 181
  • 221
2

You can use the annotation @Test(expected = TheClassException.class) to write a test which is supposed to throws the exception of class TheClassException

Alexis C.
  • 87,500
  • 20
  • 164
  • 172