开发者

Ignoring Maven/Scala unit test files

开发者 https://www.devze.com 2023-01-27 06:38 出处:网络
I am writing my unit test cases for a Java project using Scala (JUnit 4). I am running the tests using Maven.

I am writing my unit test cases for a Java project using Scala (JUnit 4). I am running the tests using Maven.

I have written a src/test/scala/com.xxx.BaseTest class for the tests to provide some common functionality (@BeforeClass, etc.), but no actual @Test cases.

Whenever I run the tests using mvn on the command line, it insists on trying to look for tests in the BaseTest class, and gets an error because there are none present.

Other than using an @Ignore, is there any way to have Maven/Scala/Surefire not try to run the BaseTest class? Adding the @Ignore is not a big deal, but my test run shows one more test than I actually have with the label "Skipped: 1".

UPDATE: I found a solution. I renamed BaseTest to Base; Maven now ignores it. Is there any o开发者_Go百科ther way?


You can either rename the base test class not to have *Test ending, for example BaseTestCase.java. This is what I would recommend.

Most likely maven executes tests with surefire plugin, so alternatively you just can configure surefire plugin to skip BaseTest.java. I think, by default surefire assumes that all classes ending with *Test are test classes. Something like this in the pom.xml.

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <excludes>
            <exclude>**/BaseTest.java</exclude>
          </excludes>
        </configuration>
      </plugin>
    </plugins>
  </build>
0

精彩评论

暂无评论...
验证码 换一张
取 消