Skip all testcase for specific Class using Assume.assumeTrue() using jUnit
package myWorkjUnit; import org.junit.After; import org.junit.AfterClass; import org.junit.Assume; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; public class LearnAfterBefore { public static boolean checkThisBeforeRunThisClass(){ // return true; return false; } @BeforeClass public static void testLoadConfiguration(){ System.out.println("Load configuration files"); System.out.println("initilize Excel files object"); Assume.assumeTrue(checkThisBeforeRunThisClass()); } @Before public void testsetUp() { System.out.println("Open browser"); System.out.println("Navigate URL"); } @Ignore @Test public void testAdvancedSearch() { System.out.println("Search on website"); } @Test public void testVerifySearchResult(){ System.out.println("Verify search result"); } @After public void testtearDown() { System.out.println("Close Browser"); } @AfterClass public static void testReportResult(){ System.out.println("Report result"); } }
Reference : Assume (JUnit API)
Sample example to learn @Test and junit – Test (JUnit API)
@Test
The annotation @Test identifies that a method is a test method.
Denotes a test method. Can be used with expected to assert expected results on the object under test.
package myWorkjUnit; import org.junit.Test; public class firstjunitprogram { @Test public void Divide() { System.out.println("Result - " + divide(10, 5)); } @Test public void substraction(){ System.out.println("Result - " + substraction(10, 5)); } @Test public void Addition(){ System.out.println("Result - " + addition(10, 5)); } public int divide(int x, int y) { return x / y; } public int addition(int x, int y) { return (x+y); } public int substraction(int x, int y) { return (x-y); } }
Reference Link 1