Is it possible to run a junit test from an intellij plugin

I have a database that stores the results of my tests. I am interested in writing a plugin for intellij13 that will allow me to restart the test crashes from the database using the JUnit launch configuration. I can not find documentation on this.

I would like to see an example for some method like:

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

+4
source share
1 answer

I looked through IntelliJ 13.x and I managed to create a JUnit runtime configuration. You need to do the following.

META-INF/plugin.xml JUnit, JUnit .

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

JUnit. , , .

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);

, JUnit .

enter image description here

+4

Source: https://habr.com/ru/post/1523645/


All Articles