UPDATE: I should have included the original POM file (below), and the fact that I did attempt solutions from JUnit's @TestMethodOrder annotation not working
What I'm Trying to Do: Run JUnit tests in a specific order.
What's wrong
- Current order notation is incorrect or ignored. With each run the order randomly changes (no changes in code). I have ~ 5 additional methods to test, and the test order becomes more important.
- Used https://junit.org/junit5/docs/current/user-guide/ section 2.9 as guide.
Environment:
- JUnit 5.6.0
- Java 16
- Netbeans IDE with Maven
package com.riverrat.recipebook;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
@TestMethodOrder(OrderAnnotation.class)
public class IngredientListTest {
//do stuff
@Test
@Order(1)
public void testIsEmpty(){//do stuff}
@Test
@Order(2)
public void testAddBacon(){//do stuff}
@Test
@Order(3)
public void testDeleteBaconByObject(){//do stuff}
@Test
@Order(4)
public void testDeleteBaconByInt(){//do stuff}
@Test
@Order(5)
public void testLoadAllIngredients(){//do stuff}
}
Current POM
<?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>com.riverrat</groupId>
<artifactId>RecipeBook</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
<packaging>jar</packaging>
<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-params</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>