jeudi 14 février 2019

Maven doesn't find JUnit test to run

When I try to run my tests with maven (mvn test), it seems that maven doen't find any test to run:

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running calculator.CalculatorTest
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec

Results :

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

I have read this, this, this and this questions, but it doesn't solve my problem.

I have a simple Java project using Maven and JUnit. My project structure is the following:

\_ src
  \_ main
     \_ java
        \_ calculator
           \_ Calculator.class
  \_ test
     \_ java
        \_ calculator
           \_ CalculatorTest.class

In my CalculatorTest.class file, I have this:

    package calculator;
    import org.junit.jupiter.api.Test;
    import static org.junit.jupiter.api.Assertions.*;

    public class CalculatorTest {

        @Test
        public void addABPositive() {
            Calculator calculator = new Calculator();
            int a, b, res;
            a = 5;
            b = 5;
            res = a + b;
            if (calculator.add(a, b) != res) {
                fail("a and b positive");
            }
        }
    }

My pom.xml file is (auto-generated by IntelliJ):

    <?xml version="1.0" encoding="UTF-8"?>
    <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>HelloWorld</groupId>
        <artifactId>HelloWorld</artifactId>
        <version>1.0-SNAPSHOT</version>
        <dependencies>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-api</artifactId>
                <version>5.0.0</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
        <properties>
            <maven.compiler.source>1.6</maven.compiler.source>
            <maven.compiler.target>1.6</maven.compiler.target>
        </properties>
    </project>

I don't know what I'm doing wrong. Maybe the dependencies, wrong version of JUnit ?

Thank for your help.

Aucun commentaire:

Enregistrer un commentaire