use of org.jacoco.core.runtime.RuntimeData in project jacoco by jacoco.
the class AgentTest method startup_should_log_exception.
@Test
public void startup_should_log_exception() throws Exception {
final Exception expected = new Exception();
Agent agent = new Agent(options, this) {
@Override
IAgentOutput createAgentOutput() {
return new IAgentOutput() {
public void startup(AgentOptions options, RuntimeData data) throws Exception {
throw expected;
}
public void shutdown() {
}
public void writeExecutionData(boolean reset) {
}
};
}
};
agent.startup();
assertSame(expected, loggedException);
}
use of org.jacoco.core.runtime.RuntimeData in project jacoco by jacoco.
the class FileOutputTest method testInvalidDestFile.
@Test(expected = IOException.class)
public void testInvalidDestFile() throws Exception {
AgentOptions options = new AgentOptions();
options.setDestfile(folder.newFolder("folder").getAbsolutePath());
FileOutput controller = new FileOutput();
// Startup should fail as the file can not be created:
controller.startup(options, new RuntimeData());
}
use of org.jacoco.core.runtime.RuntimeData in project dspot by STAMP-project.
the class JacocoExecutor method executeJacoco.
public CoverageResults executeJacoco(CtType<?> testClass) {
final String testClassesDirectory = this.program.getProgramDir() + "/" + this.program.getTestClassesDir();
final RuntimeData data = new RuntimeData();
final ExecutionDataStore executionData = new ExecutionDataStore();
final SessionInfoStore sessionInfos = new SessionInfoStore();
URLClassLoader classLoader;
try {
classLoader = new URLClassLoader(new URL[] { new File(testClassesDirectory).toURI().toURL() }, this.internalClassLoader);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
final String resource = testClass.getQualifiedName().replace('.', '/') + ".class";
try {
this.internalClassLoader.addDefinition(testClass.getQualifiedName(), IOUtils.toByteArray(classLoader.getResourceAsStream(resource)));
runtime.startup(data);
final TestListener listener = TestLauncher.run(this.configuration, this.internalClassLoader, testClass);
if (!listener.getFailingTests().isEmpty()) {
LOGGER.warn("Some test(s) failed during computation of coverage:" + AmplificationHelper.LINE_SEPARATOR + listener.getFailingTests().stream().map(Failure::toString).collect(Collectors.joining(AmplificationHelper.LINE_SEPARATOR)));
}
data.collect(executionData, sessionInfos, false);
runtime.shutdown();
clearCache(this.internalClassLoader);
return coverageResults(executionData);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.jacoco.core.runtime.RuntimeData in project dspot by STAMP-project.
the class JacocoExecutor method executeJacoco.
public Map<String, CoverageResults> executeJacoco(CtType<?> testClass, Collection<String> methodNames) {
final String testClassesDirectory = this.program.getProgramDir() + "/" + this.program.getTestClassesDir();
final String classesDirectory = this.program.getProgramDir() + "/" + this.program.getClassesDir();
URLClassLoader classLoader;
try {
classLoader = new URLClassLoader(new URL[] { new File(testClassesDirectory).toURI().toURL() }, this.internalClassLoader);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
final String resource = testClass.getQualifiedName().replace('.', '/') + ".class";
try {
this.internalClassLoader.addDefinition(testClass.getQualifiedName(), IOUtils.toByteArray(classLoader.getResourceAsStream(resource)));
final RuntimeData data = new RuntimeData();
this.runtime.startup(data);
final JacocoListener jacocoListener = new JacocoListener(data, classesDirectory);
final TestListener listener = TestLauncher.run(this.configuration, this.internalClassLoader, testClass, methodNames, jacocoListener);
if (!listener.getFailingTests().isEmpty()) {
LOGGER.warn("Some test(s) failed during computation of coverage:" + AmplificationHelper.LINE_SEPARATOR + listener.getFailingTests().stream().map(Failure::toString).collect(Collectors.joining(AmplificationHelper.LINE_SEPARATOR)));
}
this.runtime.shutdown();
clearCache(this.internalClassLoader);
return jacocoListener.getCoverageResultsMap();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations