feat: add ignored tests and update run from java
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.ignore;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public abstract class AbstractClassUnitTest {
|
||||
|
||||
@Before
|
||||
public void beforeSetUp() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenClassIsAbstract_thenTestsNeedImpl() {
|
||||
fail();
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterSetDown() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.ignore;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@Ignore("Test class not ready yet")
|
||||
public class IgnoreClassUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenClassIsIgnored_thenTestsDoNotRun() {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.ignore;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IgnoreMethodUnitTest {
|
||||
|
||||
@Ignore("This method not ready yet")
|
||||
@Test
|
||||
public void whenMethodIsIgnored_thenTestsDoNotRun() {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.ignore;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class IgnoredBadNameTestClass {
|
||||
|
||||
@Test
|
||||
public void whenClassHasBadName_thenOnBuildTestsDoNotRun() {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.baeldung.runfromjava;
|
||||
|
||||
import com.baeldung.ignore.IgnoreClassUnitTest;
|
||||
import com.baeldung.ignore.IgnoreMethodUnitTest;
|
||||
import junit.extensions.ActiveTestSuite;
|
||||
import junit.extensions.RepeatedTest;
|
||||
import junit.framework.JUnit4TestAdapter;
|
||||
@@ -12,6 +14,13 @@ import org.junit.runner.notification.Failure;
|
||||
|
||||
public class RunJUnit4TestsFromJava {
|
||||
|
||||
public static void runIgnored() {
|
||||
JUnitCore junit = new JUnitCore();
|
||||
junit.addListener(new TextListener(System.out));
|
||||
resultReport(junit.run(IgnoreClassUnitTest.class));
|
||||
resultReport(junit.run(IgnoreMethodUnitTest.class));
|
||||
}
|
||||
|
||||
public static void runOne() {
|
||||
JUnitCore junit = new JUnitCore();
|
||||
junit.addListener(new TextListener(System.out));
|
||||
@@ -66,11 +75,7 @@ public class RunJUnit4TestsFromJava {
|
||||
}
|
||||
|
||||
public static void resultReport(Result result) {
|
||||
System.out.println("Finished. Result: Failures: " +
|
||||
result.getFailureCount() + ". Ignored: " +
|
||||
result.getIgnoreCount() + ". Tests run: " +
|
||||
result.getRunCount() + ". Time: " +
|
||||
result.getRunTime() + "ms.");
|
||||
System.out.println("Finished. Result: Failures: " + result.getFailureCount() + ". Ignored: " + result.getIgnoreCount() + ". Tests run: " + result.getRunCount() + ". Time: " + result.getRunTime() + "ms.");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
@@ -88,6 +93,9 @@ public class RunJUnit4TestsFromJava {
|
||||
|
||||
System.out.println("\nRunning repeated suite tests:");
|
||||
runRepeatedSuite();
|
||||
|
||||
System.out.println("\nRunning ignored tests:");
|
||||
runIgnored();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user