Legacy tests with Maven

The following is the image we want to run the  legacy test (JUnit 4 in this case) inside the JUnit Plaform:

package io.github.bonigarcia;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class LegacyJUnit4Test {

@Test
public void myFirstTest() {
String message = "1+1 should be equal to 2";
System.out.println(message);
assertEquals(message, 2, 1 + 1);
}

}

To that aim, in Maven, we first need to include the old JUnit 4 dependency in our pom.xml, as follows:

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

Then, we need to include maven-surefire-plugin, using the following dependencies for the plugin: the Test Engine (junit-vintage-engine) and the Test Launcher (junit-platform-surefire-provider):

<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.vintage.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

The execution from the command line will also be using the command mvn test:

Running Legacy tests with Maven
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.196.244