As described inwards my previous post, We tin practise junit test suite to execute multiple bear witness cases from ane place. See illustration of my previous post. junittest2 bird convey two @Test methods. Now If I wants to exclude/Ignore 1st @Test method from execution as well as wants to execute exclusively 2d @Test method as well as thus how can I practise It? Ignoring specific bear witness inwards junit test is really easy.
@Ignore annotation
We tin work JUnit's has inbuilt @Ignore musical note earlier @Test method to Ignore that specific webdriver bear witness from execution. Let nosotros use @Ignore musical note practically inwards our bear witness as well as and thus divulge its execution result.
My scenario is to ignore 1st @Test method from execution thus i withdraw to pose @Ignore musical note inwards my bear witness earlier 1st @Test method every bit bellow.
@Ignore @Test populace void test1() throws InterruptedException{ }
Here, @Ignore musical note volition exclude test1() method from execution.
Copy bellow given Ignoring @Test method(test1()) purpose amongst @Ignore musical note as well as supersede it will @Test method purpose given on Step three (Create 2d bear witness case) of THIS EXAMPLE (Note : @Test method purpose which needs to supersede is marked amongst pink color inwards that illustration post).
//To ignore this @Test method from execution @Ignore @Test populace void test1() throws InterruptedException{ driver.findElement(By.xpath("//input[@name='fname']")).sendKeys("junittest2 class-test1"); System.out.print("\njunittest2 class-test1 method is executed"); Thread.sleep(2000); }
Now when y'all run amount bear witness suite(junittestsuite.java) as well as thus on completion of junit bear witness suite execution, y'all volition larn bellow given number inwards console.
junittest1 bird is executed
junittest2 class-test2 method is executed
As per console result, ignored test(test1()) is non executed.
JUnit bear witness execution study volition looks similar bellow.
This way, Junit's @Ignore musical note volition help us to ignore specific bear witness from execution.