B
B
borisovdenis2017-10-08 23:26:26
Java
borisovdenis, 2017-10-08 23:26:26

Why are JUnit tests not running in maven?

Essence: There was a small educational project on Java 1.5. Everything in it worked, and the tests were also run. Such is the pom.xml. Which was generated from the quickstart archetype.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>ru.intodayer</groupId>
  <artifactId>test-arraylist</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>test-arraylist</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

  <dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>5.0.0</version>
    <scope>test</scope>
  </dependency>

</dependencies>
</project>

But then it was necessary to add work with the Predicate interface with implementation in the form of a lambda (this is the condition of the task). And because lambdas have been supported since Java 8. It was necessary to add the following in pom.xml in the properties block:
<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

I don’t know for sure after that or not, but this could be the reason, the tests are not run. This is what I see every time I run the mvn test command.
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
Run the mvn clean command.
Help, please, to solve a problem. Either way, I'm just doing something wrong!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey, 2017-10-09
@TheKnight

Have you tried google? Tyk!
There is an example pom.xml at the end of the article. It is not difficult to understand it and try to prescribe what you need. If it doesn't help, we'll look into it further.

S
seralekseenko, 2020-05-27
@seralekseenko

Just ran into the same problem.
Experimentally, I found out what needs to be added to dependencies and plugins maven-surefire-plugin.
Example from pom.xml:

.............
<dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.6.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.2</version>
        </dependency>
    </dependencies>

    <build>
        <directory>${project.basedir}/target</directory>
        <outputDirectory>${project.build.directory}/classes</outputDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
            </plugin>
        </plugins>
    </build>
.........

Dependence on junit-platform-runner, in this issue, I did not feel in my project.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question