【发布时间】:2012-07-09 12:52:33
【问题描述】:
我想使用 maven 运行单个测试 这是我的 pom.xml:
朱尼特 朱尼特 4.8.1 测试 org.seleniumhq.selenium.client-drivers selenium-java-client-driver 1.0.2
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0-alpha-1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2.1-b03</version>
<scope>provided</scope>
</dependency>
网络测试自动化 org.apache.maven.plugins Maven 战争插件 2.0.2
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.0-beta-1</version>
</plugin>
<!-- Start the tomcat server and Deploy the war -->
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.2.2</version>
<configuration>
<fork>true</fork>
<wait>false</wait>
<container>
<containerId>tomcat7x</containerId>
<type>installed</type>
<home>${env.CATALINA_HOME}</home>
</container>
<!-- <executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
<goal>deploy</goal>
</goals>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions> -->
</configuration>
<!-- Start the selenium server -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start-server</goal>
</goals>
<configuration>
<background>true</background>
<logOutput>true</logOutput>
</configuration>
</execution>
<execution>
停止
整合后测试
停止服务器
org.apache.maven.plugins
maven-surefire-插件
2.4.3
org.junit:com.springsource.org.junit
**/功能/*Test.java
<!-- Running the tests in the functional tests package
during the integration tests phase. -->
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
错误的 没有任何 **/功能/*Test.java
</project>
我使用了这个命令:mvn -Dtest=MyTestClass test
我得到这个错误:
我试过这个命令,但它运行所有测试而不是指定的测试mvn -Dit.test=MyTestClass verify
【问题讨论】:
-
您尝试运行单个测试用例还是单个类中的所有测试用例?此外,您使用的是真正旧版本的 maven-surefire-plugin(最近的版本:2.12),对于集成测试,您应该使用 maven-failsafe-plugin。
-
@khmarbaise 我尝试运行单个测试类
-
对于您给定的参数,需要 maven-failsafe-plugin。但我没有在你的 pom 摘录中看到它。此外,如果您尝试运行集成测试,则需要进入正确的生命周期(mvn verify 而不是 mvn test),因为 mvn test 仅负责运行单元测试。
-
这意味着没有单元测试并且 maven-failsafe-plugin 负责这些测试。
-
首先是 sonatype 书籍:sonatype.com/Support/Books,然后是 khmarbaise.github.com/maui