2014-01-25 35 views
4

我有一个存储我的测试结果的数据库。我有兴趣为intellij13编写一个插件,它可以让我使用JUnit运行配置从数据库中重新运行测试失败。我找不到关于此的任何文档。我可以从intellij插件开始junit测试

我想看看一些方法的例子,如:

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

+0

[我如何从我的Java应用程序中运行JUnit测试?](http://stackoverflow.com/questions/2543912/how-do-i-run-junit-tests-from-inside -my-java-application) – kukido

+0

@kukido我的问题不是关于通常以编程方式运行JUnit测试。我想利用intellij已经提供的运行操作。 – munk

+0

我道歉,坏问题的理解。上次我查看了12.x中的可用选项,并且没有可用于创建JUnit运行配置的公共类。我没有检查13.x,也许它变得更加开放。我建议获取Community Edition的源代码并查找JUnit运行配置。如果您发现有趣的事,请更新问题。 – kukido

回答

4

我看着的IntelliJ 13.x和我能够创建JUnit运行时配置。您需要执行以下操作。

在你的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

+0

实际上我看不到'com.intellij.execution.junit.JUnitConfigurationType'类。你能否更新你的答案?我需要使用它的'虚拟文件'(或'PsiFile')作为我的IntelliJ插件的输入来运行**测试类(具有@Test注释的类)**。 – Emadpres

相关问题