Search in sources :

Example 1 with BlockJUnit4ClassRunner

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));
}
Also used : PlainJUnit4TestCaseWithSingleTestWhichFails(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichFails) UniqueId(org.junit.platform.engine.UniqueId) RunnerTestDescriptor(org.junit.vintage.engine.descriptor.RunnerTestDescriptor) Description.createTestDescription(org.junit.runner.Description.createTestDescription) Description(org.junit.runner.Description) BlockJUnit4ClassRunner(org.junit.runners.BlockJUnit4ClassRunner) VintageTestDescriptor(org.junit.vintage.engine.descriptor.VintageTestDescriptor) Test(org.junit.jupiter.api.Test)

Example 2 with BlockJUnit4ClassRunner

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;
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) BlockJUnit4ClassRunner(org.junit.runners.BlockJUnit4ClassRunner)

Example 3 with BlockJUnit4ClassRunner

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);
}
Also used : Description(org.junit.runner.Description) BlockJUnit4ClassRunner(org.junit.runners.BlockJUnit4ClassRunner) Test(org.junit.Test)

Example 4 with BlockJUnit4ClassRunner

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());
}
Also used : BlockJUnit4ClassRunner(org.junit.runners.BlockJUnit4ClassRunner) CategoryFilter(org.junit.experimental.categories.Categories.CategoryFilter) Test(org.junit.Test)

Example 5 with BlockJUnit4ClassRunner

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());
}
Also used : Field(java.lang.reflect.Field) BlockJUnit4ClassRunner(org.junit.runners.BlockJUnit4ClassRunner) ArkBootRunner(com.alipay.sofa.ark.springboot.runner.ArkBootRunner) TestClassLoader(com.alipay.sofa.ark.container.test.TestClassLoader) ArkEvent(com.alipay.sofa.ark.spi.event.ArkEvent) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

BlockJUnit4ClassRunner (org.junit.runners.BlockJUnit4ClassRunner)14 Test (org.junit.Test)8 Description (org.junit.runner.Description)4 RunNotifier (org.junit.runner.notification.RunNotifier)4 CategoryFilter (org.junit.experimental.categories.Categories.CategoryFilter)3 Field (java.lang.reflect.Field)2 Test (org.junit.jupiter.api.Test)2 UniqueId (org.junit.platform.engine.UniqueId)2 Description.createTestDescription (org.junit.runner.Description.createTestDescription)2 InitializationError (org.junit.runners.model.InitializationError)2 RunnerTestDescriptor (org.junit.vintage.engine.descriptor.RunnerTestDescriptor)2 VintageTestDescriptor (org.junit.vintage.engine.descriptor.VintageTestDescriptor)2 PlainJUnit4TestCaseWithSingleTestWhichFails (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichFails)2 TestClassLoader (com.alipay.sofa.ark.container.test.TestClassLoader)1 ArkEvent (com.alipay.sofa.ark.spi.event.ArkEvent)1 ArkBootRunner (com.alipay.sofa.ark.springboot.runner.ArkBootRunner)1 File (java.io.File)1 EclipseCompiler (org.eclipse.jdt.internal.compiler.tool.EclipseCompiler)1 CaptureLog (org.evosuite.testcarver.capture.CaptureLog)1 JUnitCore (org.junit.runner.JUnitCore)1