O'Reilly logo

Mastering Software Testing with JUnit 5 by Boni García

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required