Search in sources :

Example 56 with Description

use of org.junit.runner.Description in project junit5 by junit-team.

the class OrFilterTests method evaluatesMultipleFilters.

@Test
void evaluatesMultipleFilters() {
    Filter filter1 = mockFilter("foo", false);
    Filter filter2 = mockFilter("bar", true);
    OrFilter orFilter = new OrFilter(asList(filter1, filter2));
    assertEquals("foo OR bar", orFilter.describe());
    Description description = Description.createTestDescription(getClass(), "evaluatesMultipleFilters");
    assertTrue(orFilter.shouldRun(description));
    verify(filter1).shouldRun(same(description));
    verify(filter2).shouldRun(same(description));
}
Also used : Description(org.junit.runner.Description) Filter(org.junit.runner.manipulation.Filter) Test(org.junit.jupiter.api.Test)

Example 57 with Description

use of org.junit.runner.Description 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 58 with Description

use of org.junit.runner.Description in project junit5 by junit-team.

the class ConfigurableRunner method getDescription.

@Override
public Description getDescription() {
    Description suiteDescription = Description.createSuiteDescription(testClass);
    ChildCount childCountAnnotation = testClass.getAnnotation(ChildCount.class);
    int childCount = Optional.ofNullable(childCountAnnotation).map(ChildCount::value).orElse(0);
    // @formatter:off
    range(0, childCount).mapToObj(index -> Description.createTestDescription(testClass, "Test #" + index)).forEach(suiteDescription::addChild);
    // @formatter:on
    return suiteDescription;
}
Also used : IntStream.range(java.util.stream.IntStream.range) Runner(org.junit.runner.Runner) Optional(java.util.Optional) Target(java.lang.annotation.Target) Description(org.junit.runner.Description) ElementType(java.lang.annotation.ElementType) Retention(java.lang.annotation.Retention) RetentionPolicy(java.lang.annotation.RetentionPolicy) Description(org.junit.runner.Description)

Example 59 with Description

use of org.junit.runner.Description in project junit5 by junit-team.

the class UniqueIdReaderTests method readsUniqueId.

@Test
void readsUniqueId(LogRecordListener listener) {
    Description description = createTestDescription("ClassName", "methodName", "uniqueId");
    Serializable uniqueId = new UniqueIdReader().apply(description);
    assertEquals("uniqueId", uniqueId);
    assertThat(listener.stream(UniqueIdReader.class)).isEmpty();
}
Also used : Serializable(java.io.Serializable) Description.createTestDescription(org.junit.runner.Description.createTestDescription) Description(org.junit.runner.Description) Test(org.junit.jupiter.api.Test)

Example 60 with Description

use of org.junit.runner.Description in project tck by dmn-tck.

the class DmnTckRunner method runChild.

@Override
protected void runChild(TestCases.TestCase testCase, RunNotifier runNotifier) {
    Description description = this.children.get(testCase);
    try {
        runNotifier.fireTestStarted(description);
        vendorSuite.beforeTest(description, context, testCase);
        TestResult result = vendorSuite.executeTest(description, context, testCase);
        switch(result.getResult()) {
            case SUCCESS:
                runNotifier.fireTestFinished(description);
                break;
            case IGNORED:
                runNotifier.fireTestIgnored(description);
                break;
            case ERROR:
                runNotifier.fireTestFailure(new Failure(description, new RuntimeException(result.toStringWithLines())));
                break;
        }
        if (resultFile != null) {
            String relativePath = relativePath(folder);
            resultFile.append(String.format("\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"\n", relativePath, description.getClassName(), description.getMethodName(), result.getResult().toString(), result.getMsg()));
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        vendorSuite.afterTest(description, context, testCase);
        runNotifier.fireTestFinished(description);
    }
}
Also used : Description(org.junit.runner.Description) Failure(org.junit.runner.notification.Failure)

Aggregations

Description (org.junit.runner.Description)309 Test (org.junit.Test)119 Failure (org.junit.runner.notification.Failure)57 Result (org.junit.runner.Result)32 ArrayList (java.util.ArrayList)25 RunListener (org.junit.runner.notification.RunListener)23 IOException (java.io.IOException)22 Request (org.junit.runner.Request)21 Method (java.lang.reflect.Method)18 JUnitCore (org.junit.runner.JUnitCore)17 Test (org.junit.jupiter.api.Test)14 Filter (org.junit.runner.manipulation.Filter)14 File (java.io.File)13 Runner (org.junit.runner.Runner)13 Statement (org.junit.runners.model.Statement)13 LoggingListener (org.elasticsearch.test.junit.listeners.LoggingListener)12 RunNotifier (org.junit.runner.notification.RunNotifier)12 JUnit4TestListener (com.intellij.junit4.JUnit4TestListener)10 ComparisonFailure (org.junit.ComparisonFailure)10 Description.createTestDescription (org.junit.runner.Description.createTestDescription)9