Generator-jhipster: Upgrade to JUnit 5

Created on 28 Mar 2019  路  9Comments  路  Source: jhipster/generator-jhipster

Overview of the feature request

We should upgrade to JUnit 5 because it's the latest and greatest version of JUnit and JHipster is hip!

Motivation for or Use Case

Show Java developers the latest and greatest technologies.

How

For Maven, exclude junit:junit and include junit-jupiter-engine:

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <scope>test</scope>
</dependency>
<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>

For Gradle:

testImplementation ("org.springframework.boot:spring-boot-starter-test") {
    exclude module: "junit"
    exclude group: "com.vaadin.external.google", module: "android-json"
}
testImplementation "org.junit.jupiter:junit-jupiter-engine"

In .java files:

  1. Replace org.junit.Before with org.junit.jupiter.api.BeforeEach (or BeforeAll, I'm not sure which)
  2. Replace org.junit.Test with org.junit.jupiter.api.Test
  3. Remove classes and imports no longer needed:

    1. import org.junit.runner.RunWith;

    2. import org.springframework.test.context.junit4.SpringRunner;

    3. @RunWith(SpringRunner.class)

I'm sure there's more, but this seems like the basics to get started.

$100 area java

Most helpful comment

I think it's better to do it in one go as users are going to be annoyed to have an app that is partially migrated between JUnit 4 and 5.

All 9 comments

That would be great. I just hope all our test dependencies work with it. For instance I had issues on a project with the EmbeddedKafka. Testcontainers seems to have an extension.

We could also use the vintage engine first and migrate all tests step by step to junit 5

I think it's better to do it in one go as users are going to be annoyed to have an app that is partially migrated between JUnit 4 and 5.

We should document how to run and use junit 4 tests, as e.g. spock currently still requires junit 4. Is someone working on this by the way already?

@atomfrede Is there a component that requires Spock in JHipster?

No there is not, so only a problem for users wanting to use it. So if no one is working on it yet I can do it.

@atomfrede did you start to work on this? I'd be happy to do it, may I assign it to myself?

No nothing substantial. Just tried a sample app with junit 5 but nothing regarding the generator. So go ahead!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

trajakovic picture trajakovic  路  4Comments

dronavallisaikrishna picture dronavallisaikrishna  路  3Comments

edvjacek picture edvjacek  路  3Comments

sdoxsee picture sdoxsee  路  4Comments

pascalgrimaud picture pascalgrimaud  路  4Comments