How to run unit test with coverage in plugin?

Answered

I got the JUnitConfiguration,and run with CoverageExecutor and DefaultJavaCoverageRunner like below:

RunConfiguration configuration = getOrCreateConfiguration(project, psiClass);
        Executor executor = ExecutorRegistry.getInstance().getExecutorById("Coverage");
        ExecutionEnvironmentBuilder builder = ExecutionEnvironmentBuilder.createOrNull(executor, configuration);
        try {
            ExecutionEnvironment environment = builder.build();
//            DefaultJavaProgramRunner runner = new DefaultJavaProgramRunner();
//            JaCoCoCoverageRunner runner = new JaCoCoCoverageRunner();
            DefaultJavaCoverageRunner runner = new DefaultJavaCoverageRunner();
            runner.execute(environment);

but there is no coverage data generated

0
2 comments

Luofeng Qzp hi! 

You just need one extra step: call `com.intellij.execution.configurations.coverage.JavaCoverageEnabledConfiguration#getFrom` – this will mark your run configuration as suitable for coverage

2

Add builder.runnerSettings(new CoverageRunnerData()) worked,Thanks。

0

Please sign in to leave a comment.