Search in sources :

Example 51 with TestIdentifier

use of org.junit.platform.launcher.TestIdentifier in project junit5 by junit-team.

the class LegacyReportingUtils method getClassName.

/**
 * Get the class name for the supplied {@link TestIdentifier} using the
 * supplied {@link TestPlan}.
 *
 * <p>This implementation attempts to find the closest test identifier with
 * a {@link ClassSource} by traversing the hierarchy upwards towards the
 * root starting with the supplied test identifier. In case no such source
 * is found, it falls back to using the parent's
 * {@linkplain TestIdentifier#getLegacyReportingName legacy reporting name}.
 *
 * @param testPlan the test plan that contains the {@code TestIdentifier};
 *                 never {@code null}
 * @param testIdentifier the identifier to determine the class name for;
 *                 never {@code null}
 * @see TestIdentifier#getLegacyReportingName
 */
public static String getClassName(TestPlan testPlan, TestIdentifier testIdentifier) {
    Preconditions.notNull(testPlan, "testPlan must not be null");
    Preconditions.notNull(testIdentifier, "testIdentifier must not be null");
    for (TestIdentifier current = testIdentifier; current != null; current = getParent(testPlan, current)) {
        ClassSource source = getClassSource(current);
        if (source != null) {
            return source.getClassName();
        }
    }
    return getParentLegacyReportingName(testPlan, testIdentifier);
}
Also used : TestIdentifier(org.junit.platform.launcher.TestIdentifier) ClassSource(org.junit.platform.engine.support.descriptor.ClassSource)

Example 52 with TestIdentifier

use of org.junit.platform.launcher.TestIdentifier in project junit5 by junit-team.

the class CompositeTestExecutionListenerTests method shouldThrowOutOfMemoryExceptionAndStopListenerWithoutLog.

@Test
void shouldThrowOutOfMemoryExceptionAndStopListenerWithoutLog(LogRecordListener logRecordListener) {
    listeners.clear();
    listeners.add(new TestExecutionListener() {

        @Override
        public void executionStarted(TestIdentifier testIdentifier) {
            throw new OutOfMemoryError();
        }
    });
    var testIdentifier = getSampleMethodTestIdentifier();
    assertThatThrownBy(() -> compositeTestExecutionListener().executionStarted(testIdentifier)).isInstanceOf(OutOfMemoryError.class);
    assertNotLogs(logRecordListener);
}
Also used : EagerTestExecutionListener(org.junit.platform.launcher.core.CompositeTestExecutionListener.EagerTestExecutionListener) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) TestIdentifier(org.junit.platform.launcher.TestIdentifier) Test(org.junit.jupiter.api.Test)

Example 53 with TestIdentifier

use of org.junit.platform.launcher.TestIdentifier in project junit5 by junit-team.

the class CompositeTestExecutionListenerTests method shouldThrowOutOfMemoryExceptionAndStopEagerListenerWithoutLog.

@Test
void shouldThrowOutOfMemoryExceptionAndStopEagerListenerWithoutLog(LogRecordListener logRecordListener) {
    listeners.add(new EagerTestExecutionListener() {

        @Override
        public void executionJustStarted(TestIdentifier testIdentifier) {
            throw new OutOfMemoryError();
        }
    });
    var testIdentifier = getSampleMethodTestIdentifier();
    assertThatThrownBy(() -> compositeTestExecutionListener().executionStarted(testIdentifier)).isInstanceOf(OutOfMemoryError.class);
    assertNotLogs(logRecordListener);
}
Also used : EagerTestExecutionListener(org.junit.platform.launcher.core.CompositeTestExecutionListener.EagerTestExecutionListener) TestIdentifier(org.junit.platform.launcher.TestIdentifier) Test(org.junit.jupiter.api.Test)

Aggregations

TestIdentifier (org.junit.platform.launcher.TestIdentifier)53 Test (org.junit.jupiter.api.Test)29 TestPlan (org.junit.platform.launcher.TestPlan)23 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)17 LauncherDiscoveryRequestBuilder (org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder)11 Categories (org.junit.vintage.engine.samples.junit4.Categories)10 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)8 ReportEntry (org.apache.maven.surefire.report.ReportEntry)7 SimpleReportEntry (org.apache.maven.surefire.report.SimpleReportEntry)7 EngineDescriptor (org.junit.platform.engine.support.descriptor.EngineDescriptor)7 LinkedHashMap (java.util.LinkedHashMap)6 EnclosedJUnit4TestCase (org.junit.vintage.engine.samples.junit4.EnclosedJUnit4TestCase)6 PlainJUnit4TestCaseWithFiveTestMethods (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods)6 Map (java.util.Map)5 TestDescriptor (org.junit.platform.engine.TestDescriptor)5 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)5 NumberFormat (java.text.NumberFormat)3 ArrayList (java.util.ArrayList)3 MethodTestDescriptor (org.junit.jupiter.engine.descriptor.MethodTestDescriptor)3 Launcher (org.junit.platform.launcher.Launcher)3