Execute a JUnit test from Plugin

Hi Community

I would like to execute a JUnit test from my plugin.
I tried to add the JUnit plugin from IntelliJ to my plugin project to access the functionality of it.
But I always fail on the classloader.

It prints this message and terminates:

Class not found: "TestNumberB.java PluginClassLoader[com.yourcompany.unique.plugin.id, 1.0]"Exception in XML-RPC listener loop (java.net.SocketException: socket closed).

either:

JUnit4TestRunnerUtil.buildRequest(testClassNames, true);


or

JUnit4IdeaTestRunner jUnit4IdeaTestRunner = new JUnit4IdeaTestRunner();
jUnit4IdeaTestRunner.startRunnerWithArgs(testClassNames, null, true);


I tried to find an answer in the community edition source code as well but I couldn't find any.

Thanks in advance

Markus

2 comments

I got an answer now and just for those who want to know how it can be done I post my solution:

RunManager runManager = RunManager.getInstance(project);

RunnerAndConfigurationSettings runnerAndConfigurationSettings = runManager.createRunConfiguration(module.toString(), new TDAConfigurationType().getConfigurationFactories()[0]);
TDAConfiguration tdaConfiguration = (TDAConfiguration) runnerAndConfigurationSettings.getConfiguration();

tdaConfiguration.getPersistentData().TEST_OBJECT = JUnitConfiguration.TEST_PATTERN;
tdaConfiguration.getPersistentData().setPatterns(testClassPattern);
tdaConfiguration.getPersistentData().setScope(TestSearchScope.WHOLE_PROJECT);

tdaConfiguration.setModule(module);

tdaConfiguration.setVMParameters("-ea");
tdaConfiguration.setWorkingDirectory("X:\\");

Executor executor = DefaultRunExecutor.getRunExecutorInstance();
ProgramRunnerUtil.executeConfiguration(project, runnerAndConfigurationSettings, executor);


I implemented my own TDAConfiguration which extends the JUnitConfiguration for reusing the functionality of it.
The idea of it is to fill in the needed values of the "Edit Configuration" dialog and run this config with an executor.

0

Hi Markus,

I've been trying to follow your approach but run into a problem (I'm getting an exception [1] when trying to run tests). How would you solve it?

You can find more details here [2]. I would appreciate your help.

[1] java.lang.AssertionError: Error running SimpleTest:<br>'java 1.7' is bad configured
[2] http://devnet.jetbrains.com/message/5510598

0

Please sign in to leave a comment.