Search in sources :

Example 1 with ShardingEnvironment

use of com.google.testing.junit.runner.sharding.ShardingEnvironment in project bazel by bazelbuild.

the class JUnit4RunnerTest method testRunPassesWhenNoTestsOnCurrentShardWithFiltering.

@Test
public void testRunPassesWhenNoTestsOnCurrentShardWithFiltering() {
    config = createConfig("testThatAlwaysFails");
    shardingEnvironment = mock(ShardingEnvironment.class);
    shardingFilters = new FakeShardingFilters(Description.createTestDescription(SamplePassingTest.class, "testThatAlwaysPasses"));
    when(shardingEnvironment.isShardingEnabled()).thenReturn(true);
    JUnit4Runner runner = createRunner(SampleSuite.class);
    Result result = runner.run();
    verify(shardingEnvironment).touchShardFile();
    assertEquals(0, result.getRunCount());
    assertEquals(0, result.getFailureCount());
    assertEquals(0, result.getIgnoreCount());
}
Also used : FakeShardingFilters(com.google.testing.junit.runner.sharding.testing.FakeShardingFilters) ShardingEnvironment(com.google.testing.junit.runner.sharding.ShardingEnvironment) Result(org.junit.runner.Result) SettableCurrentRunningTest(com.google.testing.junit.runner.internal.junit4.SettableCurrentRunningTest) CurrentRunningTest(com.google.testing.junit.runner.util.CurrentRunningTest) Test(org.junit.Test)

Example 2 with ShardingEnvironment

use of com.google.testing.junit.runner.sharding.ShardingEnvironment in project bazel by bazelbuild.

the class JUnit4TestModelBuilderTest method testTouchesShardFileWhenShardingEnabled.

@Test
public void testTouchesShardFileWhenShardingEnabled() {
    Class<?> testClass = SampleTestCaseWithTwoTests.class;
    Request request = Request.classWithoutSuiteMethod(testClass);
    ShardingEnvironment mockShardingEnvironment = mock(ShardingEnvironment.class);
    ShardingFilters shardingFilters = new ShardingFilters(mockShardingEnvironment, DEFAULT_SHARDING_STRATEGY);
    JUnit4TestModelBuilder modelBuilder = builder(request, testClass.getCanonicalName(), mockShardingEnvironment, shardingFilters, xmlResultWriter);
    when(mockShardingEnvironment.isShardingEnabled()).thenReturn(true);
    when(mockShardingEnvironment.getTotalShards()).thenReturn(2);
    modelBuilder.get();
    verify(mockShardingEnvironment).touchShardFile();
}
Also used : Request(org.junit.runner.Request) ShardingFilters(com.google.testing.junit.runner.sharding.ShardingFilters) StubShardingEnvironment(com.google.testing.junit.runner.sharding.testing.StubShardingEnvironment) ShardingEnvironment(com.google.testing.junit.runner.sharding.ShardingEnvironment) Test(org.junit.Test)

Example 3 with ShardingEnvironment

use of com.google.testing.junit.runner.sharding.ShardingEnvironment in project bazel by bazelbuild.

the class JUnit4RunnerTest method testFilteringAndShardingTogetherIsSupported.

@Test
public void testFilteringAndShardingTogetherIsSupported() {
    config = createConfig("testThatAlways(Passes|Fails)");
    shardingEnvironment = mock(ShardingEnvironment.class);
    shardingFilters = new FakeShardingFilters(Description.createTestDescription(SamplePassingTest.class, "testThatAlwaysPasses"), Description.createTestDescription(SampleFailingTest.class, "testThatAlwaysFails"));
    when(shardingEnvironment.isShardingEnabled()).thenReturn(true);
    JUnit4Runner runner = createRunner(SampleSuite.class);
    Result result = runner.run();
    verify(shardingEnvironment).touchShardFile();
    assertEquals(2, result.getRunCount());
    assertEquals(1, result.getFailureCount());
    assertEquals(0, result.getIgnoreCount());
    assertEquals(Description.createTestDescription(SampleFailingTest.class, "testThatAlwaysFails"), result.getFailures().get(0).getDescription());
}
Also used : FakeShardingFilters(com.google.testing.junit.runner.sharding.testing.FakeShardingFilters) ShardingEnvironment(com.google.testing.junit.runner.sharding.ShardingEnvironment) Result(org.junit.runner.Result) SettableCurrentRunningTest(com.google.testing.junit.runner.internal.junit4.SettableCurrentRunningTest) CurrentRunningTest(com.google.testing.junit.runner.util.CurrentRunningTest) Test(org.junit.Test)

Example 4 with ShardingEnvironment

use of com.google.testing.junit.runner.sharding.ShardingEnvironment in project bazel by bazelbuild.

the class JUnit4RunnerTest method testRunFailsWhenNoTestsOnCurrentShardWithoutFiltering.

@Test
public void testRunFailsWhenNoTestsOnCurrentShardWithoutFiltering() {
    config = createConfig();
    shardingEnvironment = mock(ShardingEnvironment.class);
    shardingFilters = mock(ShardingFilters.class);
    when(shardingEnvironment.isShardingEnabled()).thenReturn(true);
    when(shardingFilters.createShardingFilter(anyListOf(Description.class))).thenReturn(new NoneShallPassFilter());
    JUnit4Runner runner = createRunner(SampleSuite.class);
    Result result = runner.run();
    assertEquals(1, result.getRunCount());
    assertEquals(1, result.getFailureCount());
    assertEquals(0, result.getIgnoreCount());
    assertTrue(result.getFailures().get(0).getMessage().contains("No tests found"));
    verify(shardingEnvironment).touchShardFile();
    verify(shardingFilters).createShardingFilter(anyListOf(Description.class));
}
Also used : Description(org.junit.runner.Description) ShardingFilters(com.google.testing.junit.runner.sharding.ShardingFilters) FakeShardingFilters(com.google.testing.junit.runner.sharding.testing.FakeShardingFilters) ShardingEnvironment(com.google.testing.junit.runner.sharding.ShardingEnvironment) Result(org.junit.runner.Result) SettableCurrentRunningTest(com.google.testing.junit.runner.internal.junit4.SettableCurrentRunningTest) CurrentRunningTest(com.google.testing.junit.runner.util.CurrentRunningTest) Test(org.junit.Test)

Example 5 with ShardingEnvironment

use of com.google.testing.junit.runner.sharding.ShardingEnvironment in project bazel by bazelbuild.

the class JUnit4RunnerTest method testShardingIsSupported.

@Test
public void testShardingIsSupported() {
    config = createConfig();
    shardingEnvironment = mock(ShardingEnvironment.class);
    shardingFilters = new FakeShardingFilters(Description.createTestDescription(SamplePassingTest.class, "testThatAlwaysPasses"), Description.createTestDescription(SampleFailingTest.class, "testThatAlwaysFails"));
    when(shardingEnvironment.isShardingEnabled()).thenReturn(true);
    JUnit4Runner runner = createRunner(SampleSuite.class);
    Result result = runner.run();
    verify(shardingEnvironment).touchShardFile();
    assertEquals(2, result.getRunCount());
    if (result.getFailureCount() > 1) {
        fail("Too many failures: " + result.getFailures());
    }
    assertEquals(1, result.getFailureCount());
    assertEquals(0, result.getIgnoreCount());
    assertEquals(2, runner.getModel().getNumTestCases());
}
Also used : FakeShardingFilters(com.google.testing.junit.runner.sharding.testing.FakeShardingFilters) ShardingEnvironment(com.google.testing.junit.runner.sharding.ShardingEnvironment) Result(org.junit.runner.Result) SettableCurrentRunningTest(com.google.testing.junit.runner.internal.junit4.SettableCurrentRunningTest) CurrentRunningTest(com.google.testing.junit.runner.util.CurrentRunningTest) Test(org.junit.Test)

Aggregations

ShardingEnvironment (com.google.testing.junit.runner.sharding.ShardingEnvironment)6 Test (org.junit.Test)6 SettableCurrentRunningTest (com.google.testing.junit.runner.internal.junit4.SettableCurrentRunningTest)4 FakeShardingFilters (com.google.testing.junit.runner.sharding.testing.FakeShardingFilters)4 CurrentRunningTest (com.google.testing.junit.runner.util.CurrentRunningTest)4 Result (org.junit.runner.Result)4 ShardingFilters (com.google.testing.junit.runner.sharding.ShardingFilters)3 StubShardingEnvironment (com.google.testing.junit.runner.sharding.testing.StubShardingEnvironment)2 Request (org.junit.runner.Request)2 Description (org.junit.runner.Description)1