Search in sources :

Example 1 with RunnerTestDescriptor

use of org.junit.vintage.engine.descriptor.RunnerTestDescriptor 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 RunnerTestDescriptor

use of org.junit.vintage.engine.descriptor.RunnerTestDescriptor in project junit5 by junit-team.

the class TestRunTests method returnsEmptyOptionalForUnknownDescriptions.

@Test
void returnsEmptyOptionalForUnknownDescriptions() throws Exception {
    Class<?> testClass = PlainJUnit4TestCaseWithSingleTestWhichFails.class;
    UniqueId runnerId = engineId().append(SEGMENT_TYPE_RUNNER, testClass.getName());
    RunnerTestDescriptor runnerTestDescriptor = new RunnerTestDescriptor(runnerId, testClass, new BlockJUnit4ClassRunner(testClass));
    Description unknownDescription = createTestDescription(testClass, "dynamicTest");
    TestRun testRun = new TestRun(runnerTestDescriptor);
    Optional<VintageTestDescriptor> testDescriptor = testRun.lookupTestDescriptor(unknownDescription);
    assertThat(testDescriptor).isEmpty();
}
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 3 with RunnerTestDescriptor

use of org.junit.vintage.engine.descriptor.RunnerTestDescriptor in project junit5 by junit-team.

the class TestClassRequestResolver method createCompleteRunnerTestDescriptor.

private RunnerTestDescriptor createCompleteRunnerTestDescriptor(Class<?> testClass, Runner runner, UniqueId engineId) {
    UniqueId id = engineId.append(SEGMENT_TYPE_RUNNER, testClass.getName());
    RunnerTestDescriptor runnerTestDescriptor = new RunnerTestDescriptor(id, testClass, runner);
    addChildrenRecursively(runnerTestDescriptor);
    return runnerTestDescriptor;
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) RunnerTestDescriptor(org.junit.vintage.engine.descriptor.RunnerTestDescriptor)

Example 4 with RunnerTestDescriptor

use of org.junit.vintage.engine.descriptor.RunnerTestDescriptor in project junit5 by junit-team.

the class TestClassRequestResolver method determineRunnerTestDescriptor.

private RunnerTestDescriptor determineRunnerTestDescriptor(Class<?> testClass, Runner runner, List<RunnerTestDescriptorAwareFilter> filters, UniqueId engineId) {
    RunnerTestDescriptor runnerTestDescriptor = createCompleteRunnerTestDescriptor(testClass, runner, engineId);
    if (!filters.isEmpty()) {
        if (runner instanceof Filterable) {
            Filter filter = createOrFilter(filters, runnerTestDescriptor);
            Runner filteredRunner = runnerTestDescriptor.toRequest().filterWith(filter).getRunner();
            runnerTestDescriptor = createCompleteRunnerTestDescriptor(testClass, filteredRunner, engineId);
        } else {
            Runner runnerToReport = (runner instanceof RunnerDecorator) ? ((RunnerDecorator) runner).getDecoratedRunner() : runner;
            logger.warn(() -> // 
            "Runner " + runnerToReport.getClass().getName() + " (used on " + testClass.getName() + // 
            ") does not support filtering" + " and will therefore be run completely.");
        }
    }
    return runnerTestDescriptor;
}
Also used : RunnerTestDescriptor(org.junit.vintage.engine.descriptor.RunnerTestDescriptor) Runner(org.junit.runner.Runner) Filter(org.junit.runner.manipulation.Filter) Filterable(org.junit.runner.manipulation.Filterable)

Aggregations

RunnerTestDescriptor (org.junit.vintage.engine.descriptor.RunnerTestDescriptor)4 UniqueId (org.junit.platform.engine.UniqueId)3 Test (org.junit.jupiter.api.Test)2 Description (org.junit.runner.Description)2 Description.createTestDescription (org.junit.runner.Description.createTestDescription)2 BlockJUnit4ClassRunner (org.junit.runners.BlockJUnit4ClassRunner)2 VintageTestDescriptor (org.junit.vintage.engine.descriptor.VintageTestDescriptor)2 PlainJUnit4TestCaseWithSingleTestWhichFails (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichFails)2 Runner (org.junit.runner.Runner)1 Filter (org.junit.runner.manipulation.Filter)1 Filterable (org.junit.runner.manipulation.Filterable)1