1

我直接从文档中将它添加到我的 pom.xml 中:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.7</version>
    <configuration>
      <skipTests>true</skipTests>
    </configuration>
  </plugin>
  <plugin>
    <groupId>org.scalatest</groupId>
    <artifactId>scalatest-maven-plugin</artifactId>
    <version>1.0</version>
    <configuration>
      <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
      <junitxml>.</junitxml>
      <filereports>TestSuite.txt</filereports>
    </configuration>
    <executions>
      <execution>
        <id>test</id>
        <goals>
          <goal>test</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

跑步mvn test给了我:

Discovery starting.
Discovery completed in 265 milliseconds.
Run starting. Expected test count is: 0
DiscoverySuite:
Run completed in 283 milliseconds.
Total number of tests run: 0
Suites: completed 1, aborted 0
Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
No tests were executed.

但是,应该已经发现并运行了 src/test/scala 下的几个测试。

我什至试着跑步mvn test-compile compile,只是想看看有没有什么东西出现。结果如预期:

[INFO] Nothing to compile - all classes are up to date

那么,他们怎么没有被发现呢?我的文件都被命名为 *Test.scala,并且像scalatest 文档中一样编写。

4

1 回答 1

4

在我当前的项目中,我们在 pom.xml 中有以下配置:

 <plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>scala-maven-plugin</artifactId>
    <version>3.2.2</version>
    <executions>
      <execution>
        <id>compile</id>
        <goals>
          <goal>compile</goal>
        </goals>
        <phase>compile</phase>
      </execution>
      <execution>
        <id>test-compile</id>
        <goals>
          <goal>testCompile</goal>
        </goals>
        <phase>test-compile</phase>
      </execution>
      <execution>
        <phase>process-resources</phase>
        <goals>
          <goal>compile</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

  <plugin>
    <groupId>org.scalatest</groupId>
    <artifactId>scalatest-maven-plugin</artifactId>
    <version>1.0</version>
    <configuration>
      <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
      <stdout>W</stdout>
    </configuration>
    <executions>
      <execution>
        <id>scala-test</id>
        <goals>
          <goal>test</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

因为很容易猜到第一个插件负责编译和资源处理,而第二个插件只在测试目标期间运行它们。

于 2017-04-27T18:44:58.163 回答