0

How to write unit test for this block of code

   if (!isVisible()) {
       throw new IllegalStateException("Not in xyz page");
   }
   return this.isAttached(DOT_ID);

If isVisible() is mocked to return false then how to write the unit test for the exception statement

Kaushik Vijayakumar
  • 615
  • 1
  • 9
  • 17

1 Answers1

6

With testng, you can annotate your test method like this :

@Test(expectedExceptions = IllegalStateException.class, 
      expectedExceptionsMessageRegExp = "...")
public void your_test() {
  [...]
}
Arnaud Denoyelle
  • 28,245
  • 14
  • 82
  • 137