2012-10-02 59 views
2

我有一個使用Maven和TestNG的Selenium項目。如何使用Maven POM文件運行testNG測試

我已經嘗試了幾種不同的方法讓我的測試運行Maven命令(我使用肯定的火插件)。 當我運行Maven時,測試不會運行。沒有錯誤。

有沒有人有一個很好的例子或教程,我可以按照使我的測試運行時,我使用mvn測試?

在此先感謝。

這裏是輸出:

C:\**************>mvn test 
[INFO] Scanning for projects... 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building Unnamed - **************:**************:jar:1.0 
[INFO] task-segment: [test] 
[INFO] ------------------------------------------------------------------------ 
[INFO] [resources:resources] 
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, 
i.e. build is platform dependent! 
[INFO] Copying 4 resources 
[INFO] [compiler:compile] 
[INFO] Nothing to compile - all classes are up to date 
[INFO] [resources:testResources] 
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, 
i.e. build is platform dependent! 
[INFO] skip non existing resourceDirectory C:\**************\src\test\res 
ources 
[INFO] [compiler:testCompile] 
[INFO] Nothing to compile - all classes are up to date 
[INFO] [surefire:test] 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESSFUL 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 2 seconds 
[INFO] Finished at: Tue Oct 02 15:14:10 BST 2012 
[INFO] Final Memory: 16M/38M 
[INFO] ------------------------------------------------------------------------ 

而且從我的POM文件的萬無一失的配置:

<plugins> 
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <configuration> 
        <encoding>iso-8859-1</encoding> 
        <source>1.6</source> 
        <target>1.6</target> 
       </configuration> 
      </plugin> 
      <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.12.4</version> 
      <configuration> 
       <suiteXmlFiles> 
        <suiteXmlFile>src/main/test_suites/local/***_Test.xml</suiteXmlFile> 
       </suiteXmlFiles> 
      </configuration> 
     </plugin> 
+0

你能夠運行你的testng XML嗎?你在XML中有什麼內容?另外,我相信***在xml名稱中是pom中的一些實際正確值。 –

+0

user64139,你找到了這個問題的答案嗎?我遇到同樣的問題,下面的答案不能解決問題。 –

回答

10

看看這個Maven Using TestNG網站。

基本上你所要做的就是向TestNG添加一個依賴項。

<dependencies> 
    [...] 
    <dependency> 
     <groupId>org.testng</groupId> 
     <artifactId>testng</artifactId> 
     <version>6.3.1</version> 
     <scope>test</scope> 
    </dependency> 
    [...] 
</dependencies> 

默認包括maven-surefire-plugin是:

<includes> 
    <include>**/Test*.java</include> 
    <include>**/*Test.java</include> 
    <include>**/*TestCase.java</include> 
</includes> 

這意味着,如果你的測試類的名稱不匹配上面有圖案,然後maven-surefire-plugin不會找到它們並運行它們。

您可以通過將這些文件添加到插件配置來更改/添加要包含的文件。

+0

好的一個。謝謝! –

相關問題