2

I converted my eclipse project into a maven project. I have following files in the test part of the project:

enter image description here

The TestException is an Exception class that us used in cases where exception should be thrown (it makes sense in this project). MultiResults and TestSyncPromise are the actual classes containing JUnit tests.

When select Run as -> 9 Maven test I get the following output:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.811 s
[INFO] Finished at: 2018-12-10T20:04:45+01:00
[INFO] Final Memory: 21M/197M
[INFO] ------------------------------------------------------------------------

When I instead select Run as -> JUnit test, the correct files are interpreted as tests.

This is what I've put into my pom.xml:

  <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <java.version>1.8</java.version>
      <junit.jupiter.version>5.0.0-M4</junit.jupiter.version>
      <junit.platform.version>1.0.0-M4</junit.platform.version>
  </properties>


  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.7.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>${junit.jupiter.version}</version>
        <scope>test</scope>
    </dependency>
  </dependencies>

How do I tell Maven which files are tests and which are just utility classes?

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
  • 1
    The behaviour is due to maven's naming convention for unit tests. Please check out this answer: https://stackoverflow.com/a/6178629/4897413 – gjoranv Dec 01 '18 at 00:40
  • @gjoranv Then why is `TestSyncPromise` not ran? – Tomáš Zato Dec 01 '18 at 01:23
  • 3
    First I would suggest to follow the convention over configuration paradigm and remove the configuration for sourceDirectory and testSourceDirectory...apart from that I would ask why are using such old version of junit-jupiter platform? Most recent 5.3.1? Another thing is which version of maven-surefire-plugin do you use? Have you checked on plain command line first? – khmarbaise Dec 01 '18 at 13:44
  • @khmarbaise Thanks for your suggestions, but none of them had any effect. I updated my question after fixing the paths in `pom.xml`, but surely you noticed that Maven is picking the right folder, so there's no surprise that it still does not work. – Tomáš Zato Dec 10 '18 at 19:11

0 Answers0