我知道你可以使用運行在某一類的所有測試:運行單個測試方法與Maven
mvn test -Dtest=classname
但我想運行一個單獨的方法和-Dtest = classname.methodname似乎並不上班。
我知道你可以使用運行在某一類的所有測試:運行單個測試方法與Maven
mvn test -Dtest=classname
但我想運行一個單獨的方法和-Dtest = classname.methodname似乎並不上班。
要運行Maven的一個測試方法,您需要提供命令:
mvn -Dtest=TestCircle#xyz test
其中TestCircle
是測試班級名稱和xyz
是測試方法。
外卡字符也有效;無論是在方法名稱和類名稱。
如果您正在測試多模塊項目,請指定測試所在的模塊-pl <module-name>
。
爲了能夠集成測試使用it.test=...
選項,而不是test=...
:
mvn -pl <module-name> -Dit.test=TestCircle#xyz integration-test
我希望有一種合併方式答案...這是正確的,但它採取的鏈接是在另一篇文章中:http://maven.apache.org/plugins/maven-surefire-plugin/examples/single-test.html – cjstehno 2011-06-28 11:54:01
我想知道如果類名應該是完全合格的類名,包名,答案是,儘管完全限定名稱的作用,也只有類名可用,但Maven會爲您查找該類。我猜如果名字不明確,它會發出錯誤。 – stivlo 2011-11-04 02:57:14
a總是得到錯誤:**沒有測試被執行!** – 2011-11-21 10:12:33
我與我的TestNG的做什麼, (對不起,JUnit的不支持此)測試案例是我一個組分配給測試,我想運行
@Test(groups="broken")
然後只需運行「MVN -Dgroups =破」。
這是一個很好的答案。在我的情況下,測試試圖運行,但一些Seam組件沒有正確設置,因此它看起來像跳過了一部分安裝代碼。 – 2010-08-11 20:32:21
正確。您需要將groups = broken放入您的@BeforeMethod中,或者執行@BeforeMethod(alwaysRun = true) – tunaranch 2010-08-12 05:36:27
請讓我知道什麼是組,這是因爲我正在編譯問題。 – 2015-01-23 13:37:55
的JUnit的新版本中包含的類別亞軍: http://kentbeck.github.com/junit/doc/ReleaseNotes4.8.html
但JUnit的釋放過程不Maven的基礎,所以Maven用戶必須手動把它自己的存儲庫。
不錯。但我不明白這是如何回答這個問題的。 – 2009-12-10 14:33:49
從maven-surefire-plugin的2.7.3版本支持Subj:http://maven.apache.org/plugins/maven-surefire-plugin/examples/single-test.html – 2011-04-04 00:36:08
通過tobrien提到的測試參數允許您使用#方法名前指定的方法。這應該適用於JUnit和TestNG。我從來沒有嘗試過,只是讀它的Surefire Plugin page:
Specify this parameter to run individual tests by file name, overriding the includes/excludes parameters. Each pattern you specify here will be used to create an include pattern formatted like **/${test}.java, so you can just type "-Dtest=MyTest" to run a single test called "foo/MyTest.java". This parameter overrides the includes/excludes parameters, and the TestNG suiteXmlFiles parameter. since 2.7.3 You can execute a limited number of method in the test with adding #myMethod or #my*ethod. Si type "-Dtest=MyTest#myMethod" supported for junit 4.x and testNg
沒有與神火2.12的問題。 這就是我在將Maven-surefire-plugin從2.12更改爲2時發生的情況。11:
MVN測試-Dtest = DesignRulesTest
Result:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project pmd: No tests were executed!
MVN測試-Dtest = DesignRulesTest
Result: [INFO] --- maven-surefire-plugin:2.11:test (default-test) @ pmd --- ... Running net.sourceforge.pmd.lang.java.rule.design.DesignRulesTest Tests run: 5, Failures: 0, Errors: 0, Skipped: 4, Time elapsed: 4.009 sec
運行一組在 單個測試類的方法使用2.7.3版本,您只能在單個測試類中運行n個測試。
注意:它支持junit 4.x和TestNG。
您必須使用以下語法
mvn -Dtest=TestCircle#mytest test
可以使用的模式太
mvn -Dtest=TestCircle#test* test
由於萬無一失2.12.1的,你只能在這個時候選擇多種方法(JUnit4X,補丁歡迎)
mvn -Dtest=TestCircle#testOne+testTwo test
在我的情況下,我不得不雙引號TestClass#測試名稱,如mvn -Dtest =「TestCircle#myTest」test – 2014-06-27 23:12:58
@PratikKhadloya任何想法如何工作的依賴測試?說,我在TestClass和test2中的test1(),test2(),test3()方法依賴於test1。我怎樣才能運行test2()? – Ziska 2014-10-28 20:05:45
我想如果你在測試中有依賴關係,那麼你做錯了什麼。每個測試應獨立於其他測試。您需要刪除它們之間的耦合。 – 2014-10-29 18:41:25
該命令有效! mvn "-DTest=JoinTeamTestCases#validateJoinTeam" test
請注意「-DTest」以大寫'T'開頭。
我也很想知道如何做到這一點。但是,如果我發現自己經常這樣做,我認爲這個測試可能會被劃分到自己的類中,所以你可以使用'mvn test -Dtest = classname'語法。 – 2009-12-09 13:57:03
你想知道如何通過命令行? 或者使用IDE(eclipse)會對你有用嗎? – 2009-12-09 14:04:37
我在看命令行。我認爲junit eclipse插件可以讓你做到這一點。 – BillMan 2009-12-09 14:21:48