How 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!!