2014-01-25 48 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

相關問題