Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Run mvn test,can find the test class, but shows Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

Ask Question
<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <includes>
                        <include>**/*Test.java</include>
                    </includes>
                </configuration>
            </plugin>

my project structrue [enter image description here][1] [1]: https://i.stack.imgur.com/qO1at.png

this is part of one of my test class:

all the package import:

package rockets.mining;
import com.google.common.collect.Lists;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rockets.dataaccess.DAO;
import rockets.dataaccess.neo4j.Neo4jDAO;
import rockets.model.Launch;
import rockets.model.LaunchServiceProvider;
import rockets.model.Rocket;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;
import static rockets.mining.MapMethod.frequencyOfListElements;
import static rockets.mining.MapMethod.sortMapByValues;
import static rockets.model.Launch.LaunchOutcome.FAILED;
import static rockets.model.Launch.LaunchOutcome.SUCCESSFUL;

my test class:

public class RocketMinerUnitTest {
    Logger logger = LoggerFactory.getLogger(RocketMinerUnitTest.class);
    private DAO dao;
    private RocketMiner miner;
    private List<Rocket> rockets;
    private List<LaunchServiceProvider> lsps;
    private List<Launch> launches;
    @BeforeEach
    public void setUp() {
        dao = mock(Neo4jDAO.class);
        miner = new RocketMiner(dao);
        rockets = Lists.newArrayList();
        lsps = Arrays.asList(
                new LaunchServiceProvider("ULA", 1990, "USA"),
                new LaunchServiceProvider("SpaceX", 2002, "USA"),
                new LaunchServiceProvider("ESA", 1975, "Europe ")
        // index of lsp of each rocket
        int[] lspIndex = new int[]{0, 0, 0, 1, 1};
        // 5 rockets
        for (int i = 0; i < 5; i++) {
            rockets.add(new Rocket("rocket_" + i, "USA", lsps.get(lspIndex[i])));
        // month of each launch
        int[] months = new int[]{1, 6, 4, 3, 4, 11, 6, 5, 12, 5};
        // index of rocket of each launch
        int[] rocketIndex = new int[]{0, 0, 0, 0, 1, 1, 1, 2, 2, 3};
        //outcome of rocket of each launch
        Launch.LaunchOutcome[] outcome=new Launch.LaunchOutcome[]{SUCCESSFUL,SUCCESSFUL,FAILED,SUCCESSFUL,FAILED,SUCCESSFUL,FAILED,SUCCESSFUL,FAILED,FAILED};
        // 10 launches
        launches = IntStream.range(0, 10).mapToObj(i -> {
            logger.info("create " + i + " launch in month: " + months[i]);
            Launch l = new Launch();
            l.setLaunchDate(LocalDate.of(2017, months[i], 1));
            l.setLaunchVehicle(rockets.get(rocketIndex[i]));
            l.setPrice(BigDecimal.valueOf(Math.random()*(1000000)+60000000));
            l.setLaunchSite("VAFB");
            l.setLaunchOutcome(outcome[i]);
            l.setOrbit("LEO");
            spy(l);
            return l;
        }).collect(Collectors.toList());
     * author Ziang Shen
    @ParameterizedTest
    @ValueSource(ints = {1, 2, 3})
    public void shouldReturnTopMostLaunchedRockets(int k){
        when(dao.loadAll(Launch.class)).thenReturn(launches);
        List<Rocket> sortedRockets=new ArrayList<Rocket>();
        for(Launch launch:launches)
            if(launch.getLaunchOutcome()==SUCCESSFUL)
                sortedRockets.add(launch.getLaunchVehicle());
        Map<Rocket,Integer> map=frequencyOfListElements(sortedRockets);
        sortedRockets.clear();
        map=sortMapByValues(map);
        for(Rocket rocket:map.keySet())
            sortedRockets.add(rocket);
        List<Rocket> launchedRockets=miner.mostLaunchedRockets(k);
        assertEquals(k,launchedRockets.size());
        assertEquals(sortedRockets.subList(0,k),launchedRockets);

this is the mvn test result:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running rockets.dataaccess.neo4j.Neo4jDAOUnitTest
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec - in rockets.dataaccess.neo4j.Neo4jDAOUnitTest
Running rockets.mining.RocketMinerUnitTest
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec - in rockets.mining.RocketMinerUnitTest
Running rockets.model.LaunchServiceProviderUnitTest
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec - in rockets.model.LaunchServiceProviderUnitTest
Running rockets.model.RocketUnitTest
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec - in rockets.model.RocketUnitTest
Running rockets.model.UserUnitTest
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec - in rockets.model.UserUnitTest
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.396 s
[INFO] Finished at: 2021-08-06T09:50:45+08:00
[INFO] ------------------------------------------------------------------------

this result shows that it did find all the unittest class,however,the result is run: 0, Failures: 0, Errors: 0, Skipped: 0.

You are using JUnit 5 (Jupiter) and an old version of maven-surefire-plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
        <includes>
            <include>**/*Test.java</include>
        </includes>
    </configuration>
</plugin>
  • Use the latest: as of 2021-08-05, either 2.22.2, either 3.0.0-M5.
  • You can remove the configuration part, since *Test is included by default.
  • See JUnit 5 documentation:

    Starting with version 2.22.0, Maven Surefire and Maven Failsafe provide native support for executing tests on the JUnit Platform. The pom.xml file in the junit5-jupiter-starter-maven project demonstrates how to use the Maven Surefire plugin and can serve as a starting point for configuring your Maven build.

    <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.8.2</version> </dependency> <dependency> <groupId>org.junit.platform</groupId> <artifactId>junit-platform-surefire-provider</artifactId> <version>1.3.2</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M5</version> </plugin> </plugins> </build>

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.