Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I start a junit test from an intellij plugin

I have a database that stores my test results. I'm interested in writing a plugin for intellij13 that will let me rerun the test failures from the database using the JUnit run configuration. I can't find any documentation on this.

I'd like to see an example for some method like:

public void runTest(String testClass, String testName) {...}

like image 650
munk Avatar asked Jan 25 '14 00:01

munk


1 Answers

I looked into IntelliJ 13.x and I was able to create JUnit runtime configuration. You need to do the following.

In your META-INF/plugin.xml add dependency on JUnit plugin, otherwise necessary JUnit plugin classes will not be available in your plugin class loader.

<depends optional="false">JUnit</depends>

Here's the sample code to create JUnit runtime configuration. Although it works, it is just a stub, you will have to populate all attributes.

import com.intellij.execution.RunManager;
import com.intellij.execution.impl.RunManagerImpl;
import com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl;
import com.intellij.execution.junit.JUnitConfigurationType;
import com.intellij.openapi.project.Project;
...
RunManagerImpl runManager = (RunManagerImpl) RunManager.getInstance(project);
JUnitConfigurationType type = JUnitConfigurationType.getInstance();
RunnerAndConfigurationSettingsImpl runnerAndConfigurationSettings = (RunnerAndConfigurationSettingsImpl)runManager.createRunConfiguration("junit test run", type.getConfigurationFactories()[0]);
runManager.addConfiguration(runnerAndConfigurationSettings, false);

And here we go, JUnit run configuration.

enter image description here

like image 135
kukido Avatar answered Sep 30 '22 04:09

kukido