我有以下单元测试:
import org.scalatest.FunSpec
import org.scalatest.Matchers._
class MyClassSpec extends FunSpec {
describe("MyClass"){
describe("Scenario 1"){
it("Condition 1") {
true shouldEqual false
}
it("Condition 2"){
true shouldEqual false
}
}
}
}
当我运行 maven 测试时,它编译得很好,但没有找到测试。这是输出:
[INFO] --- maven-surefire-plugin:2.7:test (default-test) @ project-name ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- scalatest-maven-plugin:1.0:test (test) @ project-name ---
Discovery starting.
Discovery completed in 202 milliseconds.
Run starting. Expected test count is: 0
DiscoverySuite:
Run completed in 236 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.
如输出所示,我正在使用 maven 的 scalatest 插件。这是我的 pom.xml 的相关部分:
<!-- disable surefire -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!-- enable scalatest -->
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<reportsDirectory>${project.build.directory}/scalatest-reports</reportsDirectory>
<junitxml>junit</junitxml>
<filereports>report.txt</filereports>
</configuration>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
我对设置这些东西很陌生,所以我不确定是否还有其他我没有检查的东西。如果我运行 maven clean 然后运行 maven 测试,我会得到完全相同的结果。我正在使用 ScalaTest 3.0.1 版。我有另一个项目也使用 3.0.1 成功运行了测试(我已经复制了我在两个项目之间可以找到的所有内容,这些项目看起来甚至是远程相关的)。