简体   繁体   中英

Ignoring Maven/Scala unit test files

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 other 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM