0

我在 eclipse 中设置了一个 mavenized 测试项目,我可以在 eclipse 中运行测试,但是当我尝试从命令行(使用 mvn test)运行它们时,它不运行任何测试:

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>

我究竟做错了什么?

4

2 回答 2

0

maven*Test.java默认使用通配符。您的测试应具有带有Test后缀的名称。或者你应该重新定义它maven-surefire-plugin

于 2013-10-29T17:52:13.370 回答
0

将项目布局更改为以下内容:

mocha
    src
        main
           java/com/.../MyClass.java
           resources/...
        test
           java/com/.../MyTest.java

删除<sourceDirectory>src</sourceDirectory>并允许 Maven 接受默认值。

于 2013-10-29T17:41:16.977 回答