1. I want to skip a Test method in class, How do i do that in Junit?
Ans: place @Ignore above the @Test method.
package Employee;
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.Ignore;
import org.junit.Test;
public class Test2 {
@Ignore
@Test
public void test1()
{
System.out.println(" test in test1");
}
@Test
public void test2()
{
System.out.println(" test in test2");
}
}
Output: test in test2.
2. Suppose I have a List of classes and in that number of methods but i want to execute Specific classes only and rest i want to skip?
Ans: If you want to Skip the classes just you need to place the @Ignore method above the class.
Class --1
package Employee;
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.Ignore;
import org.junit.Test;
@Ignore
public class Test1 {
@Test
public void test()
{
System.out.println("Test1");
}
}
Class -- 2
package Employee;
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.Ignore;
import org.junit.Test;
public class Test2 {
@Test
public void test1()
{
System.out.println(" test in test1");
}
@Test
public void test2()
{
System.out.println(" test in test2");
}
}
Test Runner method.
package Employee;
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@Suite.SuiteClasses({
Test1.class,Test2.class
})
public class Testrun {
}
Out Put: test in test2
Ans: place @Ignore above the @Test method.
package Employee;
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.Ignore;
import org.junit.Test;
public class Test2 {
@Ignore
@Test
public void test1()
{
System.out.println(" test in test1");
}
@Test
public void test2()
{
System.out.println(" test in test2");
}
}
Output: test in test2.
2. Suppose I have a List of classes and in that number of methods but i want to execute Specific classes only and rest i want to skip?
Ans: If you want to Skip the classes just you need to place the @Ignore method above the class.
Class --1
package Employee;
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.Ignore;
import org.junit.Test;
@Ignore
public class Test1 {
@Test
public void test()
{
System.out.println("Test1");
}
}
Class -- 2
package Employee;
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.Ignore;
import org.junit.Test;
public class Test2 {
@Test
public void test1()
{
System.out.println(" test in test1");
}
@Test
public void test2()
{
System.out.println(" test in test2");
}
}
Test Runner method.
package Employee;
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@Suite.SuiteClasses({
Test1.class,Test2.class
})
public class Testrun {
}
Out Put: test in test2
No comments:
Post a Comment