Search in sources :

Example 11 with SessionInfoStore

use of org.jacoco.core.data.SessionInfoStore 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);
    }
}
Also used : RuntimeData(org.jacoco.core.runtime.RuntimeData) MalformedURLException(java.net.MalformedURLException) ExecutionDataStore(org.jacoco.core.data.ExecutionDataStore) URLClassLoader(java.net.URLClassLoader) TestListener(fr.inria.stamp.test.listener.TestListener) SessionInfoStore(org.jacoco.core.data.SessionInfoStore) File(java.io.File) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 12 with SessionInfoStore

use of org.jacoco.core.data.SessionInfoStore in project powermock by powermock.

the class JacocoCoverageTest method getExecutionDataStore.

private ExecutionDataStore getExecutionDataStore(RuntimeData data) {
    final ExecutionDataStore executionData = new ExecutionDataStore();
    final SessionInfoStore sessionInfos = new SessionInfoStore();
    data.collect(executionData, sessionInfos, false);
    return executionData;
}
Also used : ExecutionDataStore(org.jacoco.core.data.ExecutionDataStore) SessionInfoStore(org.jacoco.core.data.SessionInfoStore)

Aggregations

ExecutionDataStore (org.jacoco.core.data.ExecutionDataStore)12 SessionInfoStore (org.jacoco.core.data.SessionInfoStore)12 Analyzer (org.jacoco.core.analysis.Analyzer)3 CoverageBuilder (org.jacoco.core.analysis.CoverageBuilder)3 IClassCoverage (org.jacoco.core.analysis.IClassCoverage)3 SessionInfo (org.jacoco.core.data.SessionInfo)3 RemoteControlReader (org.jacoco.core.runtime.RemoteControlReader)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 IMethodCoverage (org.jacoco.core.analysis.IMethodCoverage)2 RemoteControlWriter (org.jacoco.core.runtime.RemoteControlWriter)2 RuntimeData (org.jacoco.core.runtime.RuntimeData)2 TestListener (fr.inria.stamp.test.listener.TestListener)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 MalformedURLException (java.net.MalformedURLException)1 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1 URL (java.net.URL)1