How to run unit test with coverage in plugin?
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
Please sign in to leave a comment.
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
Add builder.runnerSettings(new CoverageRunnerData()) worked,Thanks。