JUnit 5 and Spring Framework 4.3.x

Is it right that JUnit 4.12 and junit-vintage-engine (from JUnit 5) can be used with Spring Framework 4.3.x? Is it possible to use junit-jupiter-api and junit-jupiter-engine (as from JUnit 5)?

+4
source share
1 answer

I assume you mean Spring integration tests, for example:

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class ExampleIT {
    @Test
    public void test() {
    }
}

This can be launched using the vintage engine.

You can also use JUnit 5 with Spring 4.3 using the prototype for Spring 5 . Jars are available on Jitpack, so to convert this test to JUnit 5, just add the Jupiter API and prototype to your dependencies, for example. for maven

<dependency>
   <groupId>com.github.sbrannen</groupId>
   <artifactId>spring-test-junit5</artifactId>
   <version>1.0.0.M3</version>
   <scope>test</scope>
</dependency>
<dependency>
   <groupId>org.junit.jupiter</groupId> 
   <artifactId>junit-jupiter-api</artifactId>
   <version>5.0.0-M3</version>
   <scope>test</scope>
</dependency>
...
<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

SpringRunner SpringExtension JUnit jupiter API:

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = Application.class)
public class ExampleIT {
    @Test
    public void test() {
    }
}

,

+11

Source: https://habr.com/ru/post/1667279/


All Articles