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
  • 755
  • 3
  • 10
  • 19

1 Answers1

6

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

@Test(expectedExceptions = IllegalStateException.class, 
      expectedExceptionsMessageRegExp = "...")
public void your_test() {
  [...]
}
Arnaud Denoyelle
  • 29,980
  • 16
  • 92
  • 148