我直接从文档中将它添加到我的 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 文档中一样编写。