我在eclipse中设置了一个mavenized测试项目,我可以在eclipse中运行测试,但是当我尝试从命令行运行它们时(使用mvn测试)它没有运行测试:
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.997s
[INFO] Finished at: Tue Oct 29 16:58:37 GMT 2013
[INFO] Final Memory: 6M/81M
[INFO] ------------------------------------------------------------------------
我的pom.xml看起来像这样:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mocha</groupId>
<artifactId>mocha</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.35.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.1</version>
</plugin>
</plugins>
</build>
</project>
我做错了什么?
答案 0 :(得分:0)
将项目布局更改为以下内容:
mocha
src
main
java/com/.../MyClass.java
resources/...
test
java/com/.../MyTest.java
删除<sourceDirectory>src</sourceDirectory>
并允许maven接受默认值。
答案 1 :(得分:0)
maven使用*Test.java
通配符。您的测试应具有测试后缀的名称。
或者你应该在maven-surefire-plugin