All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.teamscale.test_impacted.test_descriptor.JUnitClassBasedTestDescriptorResolverBase Maven / Gradle / Ivy

Go to download

A JUnit 5 engine that handles retrieving impacted tests from Teamscale and organizes their execution

There is a newer version: 34.2.0
Show newest version
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);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy