2013-07-25 82 views
0

我是新來的Maven的pom.xml中執行多個Java程序如何使用的pom.xml

有使用的pom.xml執行.java文件如果有任何 做,請拒絕方式發給我。

該Java文件具有硒代碼(Junit的代碼)

例:

package com.mycompany.app; 

import com.thoughtworks.selenium.*; 
import org.junit.BeforeClass; import org.junit.Test; import 
org.testng.annotations.AfterClass; import 
org.testng.annotations.AfterGroups; import 
org.testng.annotations.BeforeGroups; 

public class App4 { 

    @Test 
    public void Login1() throws Exception { 
     System.out.println("*******Love u mom*******"); 
    } 

} 

回答

0

最簡單的解決方案是使用exec-maven-plugin其正好用於該目的。您可以使用這樣的java目標,或者您可能需要exec目標。

<project> 
    ... 
    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>exec-maven-plugin</artifactId> 
     <version>1.2.1</version> 
     <executions> 
      <execution> 
      ... 
      <goals> 
       <goal>java</goal> 
      </goals> 
      </execution> 
     </executions> 
     <configuration> 
      <mainClass>com.example.Main</mainClass> 
      <arguments> 
      <argument>argument1</argument> 
      ... 
      </arguments> 
      <systemProperties> 
      <systemProperty> 
       <key>myproperty</key> 
       <value>myvalue</value> 
      </systemProperty> 
      ... 
      </systemProperties> 
     </configuration> 
     </plugin> 
    </plugins> 
    </build> 
    ... 
</project> 
+0

感謝重播以及如何運行的pom.xml 右鍵單擊pom.xml的編輯窗口 - >運行爲 - > Maven的測試。 我們可以在這裏找到這個pom.xml執行的輸出。 – user2251940

+0

喜khmarbaise請參見上面提到的代碼,並告訴如何執行的pom.xml也 – user2251940

+0

目前的情況已經改變,現在的事業,我們所談論的集成測試這是一個完整的不同的事情。您應該深入瞭解maven-failsafe插件來執行集成測試。 [請在此處詳細和深入地瞭解](http://khmarbaise.github.io/maui/it-example-container.html)。 – khmarbaise

0

對於運行Junit測試,您可以使用Maven Surefire Plugin。只需將它添加到您的POM:

<build> 
    ... 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.15</version> 
     </plugin> 
    </plugins> 
</build> 

默認情況下它產生在文本和XML格式的兩份報告:${basedir}/target/surefire-reports

默認情況下,它應該會找到src/test/java(Maven的慣例)下進行測試。所有在那裏發現的測試都會被執行。

+0

請告訴我如何運行pom.xml – user2251940

+0

運行pom?我想你的意思是執行maven?從命令行你可以簡單地輸入'mvn test',它將執行所有的事情,包括maven build [生命週期]的測試階段(http://maven.apache.org/guides/introduction/introduction-to-在-lifecycle.html)。如果你在Eclipse中運行,那麼右鍵單擊pom.xml窗口編輯器 - > run as - > Maven test應該可以工作。 – DB5

相關問題