aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/junit4/JUnit4TestModelBuilderTest.java
diff options
context:
space:
mode:
authorGravatar Stephen Amar <stephen@pinterest.com>2018-03-13 03:21:40 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-03-13 03:23:45 -0700
commitd95f1bf6ecca600096465dc858e0862b6539c46c (patch)
tree4a142000f93ad3e94c35232c9e80f46e74382f4d /src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/junit4/JUnit4TestModelBuilderTest.java
parent29bdf63e882f2748bf72d52032e1b0f37cc4d068 (diff)
Allow @Ignore on junit test classes
Currently a test class annotated with `@Ignore` will cause the test runner to fail with ``` Exception in thread "main" java.lang.IllegalArgumentException: Top test must be a suite at com.google.testing.junit.runner.junit4.JUnit4TestModelBuilder.get(JUnit4TestModelBuilder.java:53) ``` This change treats classes with no tests (either no @Test annotations or @Ignore at class level) as an empty test suite. The main motivation behind this is allowing an entire test class to be ignored (e.g. to quickly deal with a flaky test) without having to modify the BUILD file. This is desirable in order to reduce the likelihood that a developer forgets to update the BUILD file when removing the `@Ignore` annotation. This pull request overrides the previous pull request https://github.com/bazelbuild/bazel/pull/4073 Closes #4293. PiperOrigin-RevId: 188850828
Diffstat (limited to 'src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/junit4/JUnit4TestModelBuilderTest.java')
-rw-r--r--src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/junit4/JUnit4TestModelBuilderTest.java25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/junit4/JUnit4TestModelBuilderTest.java b/src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/junit4/JUnit4TestModelBuilderTest.java
index b409163617..c1a4efbd00 100644
--- a/src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/junit4/JUnit4TestModelBuilderTest.java
+++ b/src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/junit4/JUnit4TestModelBuilderTest.java
@@ -32,6 +32,7 @@ import com.google.testing.junit.runner.sharding.testing.StubShardingEnvironment;
import com.google.testing.junit.runner.util.FakeTicker;
import com.google.testing.junit.runner.util.Ticker;
import java.util.List;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.Description;
import org.junit.runner.Request;
@@ -92,6 +93,18 @@ public class JUnit4TestModelBuilderTest {
}
@Test
+ public void testCreateModel_topLevelIgnore() throws Exception {
+ Class<?> testClass = SampleTestCaseWithTopLevelIgnore.class;
+ Request request = Request.classWithoutSuiteMethod(testClass);
+ String testClassName = testClass.getCanonicalName();
+ JUnit4TestModelBuilder modelBuilder =
+ builder(request, testClassName, stubShardingEnvironment, null, xmlResultWriter);
+
+ TestSuiteModel testSuiteModel = modelBuilder.get();
+ assertThat(testSuiteModel.getNumTestCases()).isEqualTo(0);
+ }
+
+ @Test
public void testCreateModel_singleTestClass() throws Exception {
Class<?> testClass = SampleTestCaseWithTwoTests.class;
Request request = Request.classWithoutSuiteMethod(testClass);
@@ -140,7 +153,6 @@ public class JUnit4TestModelBuilderTest {
assertThat(model.getNumTestCases()).isEqualTo(1);
}
-
/** Sample test case with two tests. */
@RunWith(JUnit4.class)
public static class SampleTestCaseWithTwoTests {
@@ -153,6 +165,16 @@ public class JUnit4TestModelBuilderTest {
}
}
+ /** Sample test case with top level @Ignore */
+ @Ignore
+ @RunWith(JUnit4.class)
+ public static class SampleTestCaseWithTopLevelIgnore {
+ @Test
+ public void testOne() {}
+
+ @Test
+ public void testTwo() {}
+ }
/** Sample test case with one test. */
@RunWith(JUnit4.class)
@@ -162,7 +184,6 @@ public class JUnit4TestModelBuilderTest {
}
}
-
/** Sample suite with one test. */
@RunWith(Suite.class)
@SuiteClasses(SampleTestCaseWithOneTest.class)