junit testing - assertEquals for exception

后端 未结 5 900

How can I use assertEquals to see if the exception message is correct? The test passes but I don\'t know if it hits the correct error or not.

The test I am running.

5条回答
  •  一整个雨季
    2021-02-08 17:01

    Works perfectly for me.

    try{
        assertEquals("text", driver.findElement(By.cssSelector("html element")).getText());
        }catch(ComparisonFailure e){
            System.err.println("assertequals fail");
        }
    

    if assertEquals fails ComparisonFailure will handle it

提交回复
热议问题