JUnit Tutorial
Introduction to Junit JUnit Set up JUnit Architecture JUnit Annotations JUnit Fixtures Junit Assertions Junit Categories @Test Annotation Parameters Verification of Exceptions Ignoring tests Time out in JUnit tests Parameterizing tests Test Suite TestWatcher TemporaryFolder ExternalResource Theories in JUnit JUnit Test Runners Execution order of JUnit tests Assumptions in JUnit JUnit and Hamcrest Matchers Running JUnit tests in parallel JUnit and Maven Integration JUnit and Gradle Integration Executing Selenium tests using JUnit test framework Method interceptor and usage JUnit in Intellij IDEA JUnit in EclipseHow to ignore tests in junit
Sometimes you want to skip some tests. SO JUnit provides annotation called as @Ignore which helps us to ignore tests. Below example will illustrate how to use @Ignore annotation.
import org.junit.*;
import static org.junit.Assert.assertTrue;
/**
* Created by Sagar on 28-03-2016.
*/
public class IgnoreTestClass {
@Test @Ignore
public void test1(){
System.out.println("**Running test from sanity**");
assertTrue("Checking simple condition",1==1);
}
@Test
public void test2(){
System.out.println("Running test2");
Assert.assertEquals("Checking other condition","sagar","sagar");
}
}
After running above JUnit class only second test will be executed as first test method is annotated with @Ignore. We can also ignore entire test class by annotating the class by @Ignore as shown in below example.
package junit_tests;
import org.junit.*;
import static org.junit.Assert.assertTrue;
/**
* Created by Sagar on 28-03-2016.
*/
@Ignore
public class IgnoreTestClass {
@Test
public void test1(){
System.out.println("**Running test from sanity**");
assertTrue("Checking simple condition",1==1);
}
@Test
public void test2(){
System.out.println("Running test2");
Assert.assertEquals("Checking other condition","sagar","sagar");
}
}
Web development and Automation testing
solutions delivered!!