-2

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

letter Q
  • 14,735
  • 33
  • 79
  • 118

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
  • 104,088
  • 27
  • 192
  • 230
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.
  • 91,686
  • 21
  • 171
  • 177