I have the following unit tests:
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
}
}
}
}
When I run maven test, this compiles fine but the tests are not found. Here is the output:
[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.
As the output shows, I'm using the scalatest plugin for maven. Here is the relevant section of my 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>
I'm pretty new to getting this stuff set up, so I'm not sure if there is some other thing I'm not checking. I get the exact same results if I run maven clean and then maven test. I'm using ScalaTest version 3.0.1. I have another project with tests running successfully also using 3.0.1 (I've copied everything I can find between the two projects that seems even remotely related).
Naturally, the problem seems to have stemmed from some information I didn't think was relevant, so I didn't include it my original post.
The source code I wrote was a tool for unit testing, so I put it in the namespace my.cool.package.testUtilities
. The unit tests were thus in my.cool.package.testUtilities.test
. Moving the source code out of testUtilities
(to just my.cool.package
) and moving the tests to just my.cool.package.test
allowed the tests to be discovered.
Being new to the java ecosystem (previous experience in .NET), I'm not sure if this is some weird bug with the test runner, expected behavior, or if the act of moving the files to new namespaces did something else, and the namespaces themselves are irrelevant. So I'm not sure what I learned from this.