use of org.junit.runners.BlockJUnit4ClassRunner in project junit5 by junit-team.
the class TestRunTests method registersDynamicTestDescriptors.
@Test
void registersDynamicTestDescriptors() throws Exception {
Class<?> testClass = PlainJUnit4TestCaseWithSingleTestWhichFails.class;
UniqueId runnerId = engineId().append(SEGMENT_TYPE_RUNNER, testClass.getName());
RunnerTestDescriptor runnerTestDescriptor = new RunnerTestDescriptor(runnerId, testClass, new BlockJUnit4ClassRunner(testClass));
UniqueId dynamicTestId = runnerId.append(SEGMENT_TYPE_DYNAMIC, "dynamicTest");
Description dynamicDescription = createTestDescription(testClass, "dynamicTest");
VintageTestDescriptor dynamicTestDescriptor = new VintageTestDescriptor(dynamicTestId, dynamicDescription);
TestRun testRun = new TestRun(runnerTestDescriptor);
testRun.registerDynamicTest(dynamicTestDescriptor);
assertThat(testRun.lookupTestDescriptor(dynamicDescription)).contains(dynamicTestDescriptor);
assertTrue(testRun.isDescendantOfRunnerTestDescriptor(dynamicTestDescriptor));
}
use of org.junit.runners.BlockJUnit4ClassRunner in project junit4 by junit-team.
the class ParentRunnerTest method runTestWithParentRunner.
private CountingRunListener runTestWithParentRunner(Class<?> testClass) throws InitializationError {
CountingRunListener listener = new CountingRunListener();
RunNotifier runNotifier = new RunNotifier();
runNotifier.addListener(listener);
ParentRunner<?> runner = new BlockJUnit4ClassRunner(testClass);
runner.run(runNotifier);
return listener;
}
use of org.junit.runners.BlockJUnit4ClassRunner in project junit4 by junit-team.
the class ParentRunnerClassLoaderTest method testDescriptionContainCorrectTestClass.
@Test
public void testDescriptionContainCorrectTestClass() throws Exception {
Class<?> testClassWithOwnClassLoader = wrapToClassLoader(TestWithClassRule.class);
ParentRunner<?> runner = new BlockJUnit4ClassRunner(testClassWithOwnClassLoader);
Description description = runner.getDescription();
assertEquals("ParentRunner accept already instantiate Class<?> with tests, if we lost it instance, and will " + "use Class.forName we can not find test class again, because tests can be " + "located in different ClassLoader", description.getTestClass(), testClassWithOwnClassLoader);
}
use of org.junit.runners.BlockJUnit4ClassRunner in project junit4 by junit-team.
the class CategoryTest method categoryFilterLeavesOnlyMatchingMethods.
@Test
public void categoryFilterLeavesOnlyMatchingMethods() throws InitializationError, NoTestsRemainException {
CategoryFilter filter = CategoryFilter.include(SlowTests.class);
BlockJUnit4ClassRunner runner = new BlockJUnit4ClassRunner(A.class);
filter.apply(runner);
assertEquals(1, runner.testCount());
}
use of org.junit.runners.BlockJUnit4ClassRunner in project sofa-ark by alipay.
the class ArkBootRunnerTest method test.
@Test
public void test() {
Assert.assertNotNull(sampleService);
Assert.assertNotNull(pluginManagerService);
Assert.assertTrue("SampleService".equals(sampleService.say()));
ArkBootRunner runner = new ArkBootRunner(ArkBootRunnerTest.class);
Field field = ReflectionUtils.findField(ArkBootRunner.class, "runner");
Assert.assertNotNull(field);
ReflectionUtils.makeAccessible(field);
BlockJUnit4ClassRunner springRunner = (BlockJUnit4ClassRunner) ReflectionUtils.getField(field, runner);
Assert.assertTrue(springRunner.getClass().getCanonicalName().equals(SpringRunner.class.getCanonicalName()));
ClassLoader loader = springRunner.getTestClass().getJavaClass().getClassLoader();
Assert.assertTrue(loader.getClass().getCanonicalName().equals(TestClassLoader.class.getCanonicalName()));
Assert.assertEquals(0, TestValueHolder.getTestValue());
eventAdminService.sendEvent(new ArkEvent() {
@Override
public String getTopic() {
return "test-event-A";
}
});
Assert.assertEquals(10, TestValueHolder.getTestValue());
eventAdminService.sendEvent(new ArkEvent() {
@Override
public String getTopic() {
return "test-event-B";
}
});
Assert.assertEquals(20, TestValueHolder.getTestValue());
}
Aggregations