簡體   English   中英

測試單個程序包會跳過TestNG中的參數化測試

[英]Testing a single package skips parametrized tests in TestNG

總體描述

我有一個帶有參數化TestNG測試的簡單Maven項目。 該參數是通過套件XML文件指定的。 當我為整個項目運行測試時,將讀取套件XML文件,使用參數並執行參數化的測試。 但是,當我嘗試僅測試單個軟件包時,則顯然未使用套件XML文件,並且@Test on方法要求使用諸如“參數'...”之類的抱怨跳過測試,但是它具有未被標記為“ @Optional”或“已定義”。 問題是如何運行單個測試和帶有參數的測試包。

有關更多詳細信息,請參見下文。

測試整個項目

這按預期工作。 執行兩種測試方法。 一種測試方法是無參數的,另一種是參數化的,參數值是從套件XML文件中獲取的。 這等效於NetBeans中的Run \\ Test項目。

C:\Users\Andrew\Documents\NetBeansProjects\TestNGDemo>"c:\Program Files\NetBeans 8.2\java\maven\bin\mvn" test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building TestNGDemo 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ TestNGDemo ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ TestNGDemo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ TestNGDemo ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Andrew\Documents\NetBeansProjects\TestNGDemo\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ TestNGDemo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ TestNGDemo ---
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running TestSuite
testGetChangedString
getTrue
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.844 s - in TestSuite
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.702s
[INFO] Finished at: Wed Jun 06 23:42:20 ACST 2018
[INFO] Final Memory: 9M/245M
[INFO] ------------------------------------------------------------------------
C:\Users\Andrew\Documents\NetBeansProjects\TestNGDemo>

測試單個包裝

在這種情況下,僅運行一種測試方法,而無參數測試。 跳過參數化的測試方法。 這等效於右鍵單擊NetBeans中的程序包,然后選擇“測試程序包”。

C:\Users\Andrew\Documents\NetBeansProjects\TestNGDemo>"c:\Program Files\NetBeans 8.2\java\maven\bin\mvn" test -Dtest=com.endersoft.testngdemo.**.*
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building TestNGDemo 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ TestNGDemo ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ TestNGDemo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ TestNGDemo ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Andrew\Documents\NetBeansProjects\TestNGDemo\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ TestNGDemo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ TestNGDemo ---
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.endersoft.testngdemo.SimpleClassNGTest
getTrue
[WARNING] Tests run: 2, Failures: 0, Errors: 0, Skipped: 1, Time elapsed: 2.422 s - in com.endersoft.testngdemo.SimpleClassNGTest
[INFO]
[INFO] Results:
[INFO]
[WARNING] Tests run: 2, Failures: 0, Errors: 0, Skipped: 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.268s
[INFO] Finished at: Wed Jun 06 23:47:28 ACST 2018
[INFO] Final Memory: 9M/245M
[INFO] ------------------------------------------------------------------------

項目來源

可以從此處下載壓縮的項目源(非常小)

您需要單獨的XML文件才能獲得單獨的程序包。 當使用包作為參數運行TestNG時,TestNG不會自動識別XML文件,就像它不存在一樣。 因此,您有多個選項,可以在屬性文件中指定參數,也可以對其進行硬編碼,或者為每個包創建單獨的XML文件,然后可以將其作為參數傳遞。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM