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

com.teamscale.jacoco.agent.testimpact.CoverageToExecFileStrategy Maven / Gradle / Ivy

Go to download

JVM profiler that simplifies various aspects around recording and uploading test coverage

There is a newer version: 34.0.2
Show newest version
package com.teamscale.jacoco.agent.testimpact;

import com.teamscale.jacoco.agent.JacocoRuntimeController;
import com.teamscale.jacoco.agent.options.AgentOptions;
import com.teamscale.jacoco.agent.util.LoggingUtils;
import com.teamscale.report.testwise.jacoco.cache.CoverageGenerationException;
import com.teamscale.report.testwise.model.TestExecution;
import com.teamscale.report.testwise.model.TestInfo;
import org.slf4j.Logger;

import java.io.IOException;

/**
 * Strategy for appending coverage into one exec file with one session per test. Execution data will be stored in a json
 * file side-by-side with the exec file. Test executions are also appended into a single file.
 */
public class CoverageToExecFileStrategy extends TestEventHandlerStrategyBase {

	private final Logger logger = LoggingUtils.getLogger(this);

	/** Helper for writing test executions to disk. */
	private final TestExecutionWriter testExecutionWriter;

	public CoverageToExecFileStrategy(JacocoRuntimeController controller, AgentOptions agentOptions,
									  TestExecutionWriter testExecutionWriter) {
		super(agentOptions, controller);
		this.testExecutionWriter = testExecutionWriter;
	}

	@Override
	public TestInfo testEnd(String test,
							TestExecution testExecution) throws JacocoRuntimeController.DumpException, CoverageGenerationException {
		logger.debug("Test {} ended with execution {}. Writing exec file and test execution", test, testExecution);
		super.testEnd(test, testExecution);
		controller.dump();
		if (testExecution != null) {
			try {
				testExecutionWriter.append(testExecution);
				logger.debug("Successfully wrote test execution for {}", test);
			} catch (IOException e) {
				logger.error("Failed to store test execution: " + e.getMessage(), e);
			}
		}
		return null;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy