Skip to content

Provide dedicated Spring Boot starter for JUnit 5 #14716

Closed
@odrotbohm

Description

@odrotbohm

When trying to port a Spring Boot project that has previously used JUnit 4 to JUnit 5 one needs to add quite a few additional dependencies to basically get back to the very same functionality that one got with the standard test starter. This is due to the fact that in JUnit 5, a lot of functionality that had been included in JUnit itself was extracted into extensions that now live in third party projects that require explicit inclusion.

Most notabily it are the following additional libraries:

  • org.junit.jupiter:junit-jupiter-params for parameterized tests
  • org.mockito:mockito-junit-jupiter for @Mock
  • org.hamcrest:hamcrest-junit for assertThat(…)

Especially the latter is quite nasty as it in turn depends on JUnit 4.12, so that an explicit exclude is needed.

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-test</artifactId>
  <scope>test</scope>
  <exclusions>
    <exclusion>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
    </exclusion>
  </exclusions>
</dependency>

<dependency>
  <groupId>org.junit.jupiter</groupId>
  <artifactId>junit-jupiter-engine</artifactId>
  <scope>test</scope>
</dependency>

<dependency>
  <groupId>org.junit.jupiter</groupId>
  <artifactId>junit-jupiter-params</artifactId>
  <scope>test</scope>
</dependency>

<!-- 
  As indicated by Marc below this could be replaced by
  hamcrest-core to avoid the exclusion
-->
<dependency>
  <groupId>org.hamcrest</groupId>
  <artifactId>hamcrest-junit</artifactId>
  <version>2.0.0.0</version>
  <scope>test</scope>
  <exclusions>
    <exclusion>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
    </exclusion>
  </exclusions>
</dependency>

<dependency>
  <groupId>org.mockito</groupId>
  <artifactId>mockito-junit-jupiter</artifactId>
  <scope>test</scope>
</dependency>

Be sure to read the note on that list below.

It would be cool if that could be reduced to only declare a spring-boot-starter-test-junit5 (name tbd) instead of spring-boot-starter-test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions