Report Error When Test is fail using Assertion | Selenium Forum
M
Posted on 28/08/2016
Hi Ashish,
I try to fail my test so for that i used [b:pyrri6bn]Assert.assertEquals("a","c")[/b:pyrri6bn][Condition is false] in Try{} Catch{} block and used
[b:pyrri6bn]ErrorUtil.addVerificationFailure(t)[/b:pyrri6bn] method. So after executing the batch run why my this test case display as pass it should display as Fail and move ahead. I have already included [b:pyrri6bn]CustomListener.java[/b:pyrri6bn] & [b:pyrri6bn]ErrorUtil.java[/b:pyrri6bn] classes into the package.

[b:pyrri6bn]Project & Screen shot is also attached:-[/b:pyrri6bn]

[b:pyrri6bn]Code:-[/b:pyrri6bn]


package tentNgListener;
import org.testng.Assert;
import org.testng.annotations.Test;

public class YahooNews {

@Test(priority=1)
public void yahoonewsTest(){

System.out.println("Yahoo News Test class is running");
Assert.assertTrue(6<10, "Condition fail");
System.out.println("Assert will execute");

[b:pyrri6bn]try{
Assert.assertEquals("a","c");
}catch(Throwable t){
ErrorUtil.addVerificationFailure(t);
}[/b:pyrri6bn]
System.out.println("Test Fail");
}

@Test(priority=2)
public void adminLogin(){
System.out.println("Running adminLogin Test");

}
}

M
Replied on 29/08/2016

you'll have to wait a day or 2 sam.
I'm checking.


M
Replied on 30/08/2016

are you executing through testng.xml?


M
Replied on 30/08/2016

Yes i am executing through testng.xml.


M
Replied on 30/08/2016

send the project.

PS: is there any reason you want to study this. this has been replaced with soft asserts.


M
Replied on 31/08/2016

Hi Ashish,
I am sending you my Project, as per your comments about "Soft Assert" on which video you discussed it.
Currently i am studying [b:1yv22il0]MODULE -9 (PART 6 - PASSCODE - 5346)[/b:1yv22il0] and in this video no "Soft Assert" topic is not covered.Plz suggest..


M
Replied on 31/08/2016

Soft Assert are covered later in framework. there much better at error handling.

module 20 (2016)