简体   繁体   中英

Why my test are being ignored generating coverage report with Jacoco and Maven

I have the follwowing POM file:


<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>com.manning.junitbook</groupId>
    <artifactId>ch13-continuous</artifactId>
    <version>1.0-SNAPSHOT</version>

    <name>ch13-continuous</name>
    <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>

        <sonar.coverage.jacoco.xmlReportPaths>target\site\jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
        <sonar.junit.reportPaths>target\surefire-reports</sonar.junit.reportPaths>

    </properties>
    <build>
    <plugins>
        <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.8.5</version>
        <executions>
            <execution>
                <id>report</id>
                <goals>
                    <goal>report</goal>
                </goals>
                <phase>verify</phase>
            </execution>
        </executions>
       </plugin>

        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.1</version>
        </plugin>
      </plugins>
    </build>

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

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.6.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

I have created some tests. One of them, for example, test some functions from Passenger class. It code is the following:

package es.ull.passengers;

import es.ull.flights.Flight;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class PassengerTest {
    Passenger Pasajero = new Passenger("1","Paco","US");
    Flight testing = new Flight("AA9020", 100);


    @Test
    public void test_get_Name(){
        System.out.println("Testing get Name...");
        assertEquals("Paco", Pasajero.getName());
    }

    @Test
    public void test_get_Identifier(){
        System.out.println("Testing get Identifier...");
        assertEquals("1", Pasajero.getIdentifier());
    }

    @Test
    public void test_get_CountryCode(){
        System.out.println("Testing get Country Code...");
        assertEquals("US", Pasajero.getCountryCode());
    }

    @Test
    public void test_Flight(){
        System.out.println("Testing get Flight...");
        Pasajero.setFlight(testing);
        assertEquals(testing, Pasajero.getFlight());
    }

    @Test
    public void test_join_flight(){
        System.out.println("Testing join Flight...");
        Flight testing2 = new Flight("AA9023", 200);
        Pasajero.joinFlight(testing2);
        assertEquals(testing2, Pasajero.getFlight());
    }

    @Test
    public void test_to_string(){
        System.out.println("Testing toString...");
        assertEquals("Passenger Paco with identifier: 1 from US", Pasajero.toString());
    }
}

When I do "mvn verify", it generates the index.xml on targe/site. However, when I checked it, it looks like this: 在此处输入图像描述

So, I want to know why is this happening. Why isn´t considering my tests?? Here is the console output:

[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------< com.manning.junitbook:ch13-continuous >----------------
[INFO] Building ch13-continuous 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ ch13-continuous ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\jesus\Downloads\Airport\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ ch13-continuous ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ ch13-continuous ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ ch13-continuous ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ ch13-continuous ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running FlightTest
Testing number of passengers...
Testing removing Passenger...
Testing adding Passenger...
Testing flight number...
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.031 s - in FlightTest
[INFO] Running PassengerTest
Testing get Flight...
Testing toString...
Testing get Country Code...
Testing get Name...
Testing get Identifier...
Testing join Flight...
[INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 s - in PassengerTest
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 10, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ ch13-continuous ---
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.5:report (report) @ ch13-continuous ---
[INFO] Loading execution data file C:\Users\jesus\Downloads\Airport\target\jacoco.exec
[INFO] Analyzed bundle 'ch13-continuous' with 2 classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.520 s
[INFO] Finished at: 2020-12-12T13:27:22Z
[INFO] ------------------------------------------------------------------------

Is annotation @Test imported from package org.junit.jupiter.api.Test?
If that's the case, you need add maven plugin maven-surefire-plugin in pom file.
Here's maven junit5 plugin document
I think junit5 doesn't work without maven-surefire-plugin when execute maven test.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M5</version>
</plugin>

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