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);
}
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);
}
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);
}
Aggregations