Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between junit-vintage-engine and junit-jupiter-engine?

It's a two-fold question.

  1. What is the difference between junit-vintage-engine and junit-jupiter-engine?
  2. SpringBoot starter projects come with an exclusion for junit-vintage-engine. Is it to enforce the use of junit-jupiter-engine?

Below is the dependency of my SpringBoot project generated from Spring Initializr:

        <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
like image 328
Sandeep Kumar Avatar asked Dec 05 '19 10:12

Sandeep Kumar


People also ask

What is JUnit Jupiter and vintage?

JUnit Jupiter is the combination of the programming model and extension model for writing tests and extensions in JUnit 5. The Jupiter sub-project provides a TestEngine for running Jupiter based tests on the platform. JUnit Vintage provides a TestEngine for running JUnit 3 and JUnit 4 based tests on the platform.

What is JUnit vintage engine used for?

JUnit Vintage ensures that existing JUnit tests can run alongside newer tests created using JUnit Jupiter. JUnit 5's architecture also supports running multiple test engines simultaneously: you can run the JUnit Vintage test engine with virtually any other test engine that is compatible with JUnit 5.

Is JUnit 5 the same as JUnit Jupiter?

JUnit 4 came in a single artifact, blending all uses cases into one bundle. The JUnit 5 architecture promotes a better separation of concerns and provides clear APIs for testers (Jupiter) and tools (Platform).


3 Answers

junit-vintage-engine is used for running JUnit 4 tests; junit-jupiter-engine for JUnit 5 tests.

Presumably since you'll be writing only JUnit 5 tests for a new Spring Boot project, the vintage engine won't be needed, hence the default dependency exclusion in the POM.

Reference:

https://junit.org/junit5/docs/current/user-guide

like image 52
ck1 Avatar answered Oct 24 '22 09:10

ck1


Answer : 1. Based on reading i found some difference like,

junit-vintage-engine :

  • Used in Junit-4 Testing.
  • Used to call core classes and annotations.
  • 'Assert' which provide assertion methods for performing test.
  • 'Assume' used to place assumptions.
  • Use annotation like, @Ignore, @Before, etc...

junit-jupiter-engine :

  • Used in Junit-5 Testing
  • Provide some API which helpful to write test cases.
  • 'Assertions' provides utility methods of assertion condition for testing.
  • 'Assumptions' - utility method provide condition based on assumption.
  • Change the bit of annotation name like, @Disable, @BeforeAll, @BeforeEach, etc...

Answer : 2. I'm also amazed they are still providing older vintage library probably there is some reason which i don't know till now but based on current usage we'll see that in next update.

Have a nice day!!! :)

like image 5
Dhwanil Patel Avatar answered Oct 24 '22 09:10

Dhwanil Patel


First question is also related with the version of JDK. To be able to use jupiter engine, you must have Java 8 or higher. For second question; since the vintage engine is for JUnit4 and JUnit4 is greater than 10 years old, it is not recommended to be used. As far as I know, it has not been updated along this time although java has been evolved so much. I think that is why spring initializers enforce the use of junit-jupiter-engine.

like image 1
Ömer Avatar answered Oct 24 '22 09:10

Ömer