com.teamscale.test_impacted.test_descriptor.JUnitClassBasedTestDescriptorResolverBase Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of impacted-test-engine Show documentation
Show all versions of impacted-test-engine Show documentation
A JUnit 5 engine that handles retrieving impacted tests from Teamscale and organizes their execution
package com.teamscale.test_impacted.test_descriptor;
import com.teamscale.test_impacted.commons.LoggerUtils;
import org.junit.platform.engine.TestDescriptor;
import org.junit.platform.engine.TestEngine;
import java.util.Optional;
import java.util.logging.Logger;
/** Test descriptor resolver for JUnit based {@link TestEngine}s. */
public abstract class JUnitClassBasedTestDescriptorResolverBase implements ITestDescriptorResolver {
private static final Logger LOGGER = LoggerUtils.getLogger(JUnitClassBasedTestDescriptorResolverBase.class);
@Override
public Optional getUniformPath(TestDescriptor testDescriptor) {
return getClassName(testDescriptor).map(className -> {
String classNameUniformPath = className.replace(".", "/");
return classNameUniformPath + "/" + testDescriptor.getLegacyReportingName().trim();
});
}
@Override
public Optional getClusterId(TestDescriptor testDescriptor) {
Optional classSegmentName = getClassName(testDescriptor);
if (!classSegmentName.isPresent()) {
LOGGER.severe(
() -> "Falling back to unique ID as cluster id because class segment name could not be " +
"determined for test descriptor: " + testDescriptor);
// Default to uniform path.
return Optional.of(testDescriptor.getUniqueId().toString());
}
return classSegmentName;
}
/** Returns the test class containing the test. */
protected abstract Optional getClassName(TestDescriptor testDescriptor);
}