Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • Orekit Orekit
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 90
    • Issues 90
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 16
    • Merge requests 16
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Orekit
  • OrekitOrekit
  • Merge requests
  • !295

Issue 956: Migrate tests from JUnit4 to JUnit5

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Vincent CUCCHIETTI requested to merge vcucchie/orekit:issue-956 into develop Aug 24, 2022
  • Overview 1
  • Commits 57
  • Pipelines 7
  • Changes 387+

Introduction

Hey everyone,

This merge request aims to migrate all Orekit tests from JUnit4 to JUnit5.

I apologize in advance for the mess in my commits, i started from the wrong branch so i had to delete a few things (still learning git).

Process summary

In order to migrate all tests, i initially used a macro available in IntelliJ which did part of the work. Lots of CTRL + R were also used to replace old assertions with their new equivalent.

The Pom now uses the following dependencies:

  • junit-jupiter-api (v5.9.0) (essentially the core of JUnit5)
  • junit-jupiter-engine (v5.9.0) (needed because of the maven surefire plugin 2.22.0+)
  • hamcrest-library (v2.2) (was initially integrated in JUnit4 but is now independent)

Exception tests

From there i mainly had to manually replace tests that expected an exception to be thrown, which used :

@Test(expected = Exception.class)
public void shouldRaiseAnException() throws Exception {
    // ...
}

By the JUnit5 equivalent :

public void shouldRaiseAnException() throws Exception {
    Assertions.assertThrows(Exception.class, () -> {
        //...
    });
}

Temporary folder & Rule

The other tests where i had to manually intervene were the tests that used the TemporaryFolder class. In this case, the JUnit5 equivalent is the @TempDir annotation. For example, if we had :

class SomeTest {

    @Rule
    TemporaryFolder tmp = new TemporaryFolder();

   // tests ...
}

Then it was replaced with :

class SomeTest {

    @TempDir
    Path(or File) directory;

   // tests ...
}

Others

I took the opportunity to fix some documentation that didn't use some parameters anymore or with different names.

Sources

For those interested in the detailed process, here is what i used to do the migration:

  • Baeldung tutorial
  • IntelliJ tutorial
  • StackOverflow post about the TemporaryFolder issue
Edited Aug 24, 2022 by Vincent CUCCHIETTI
Assignee
Assign to
Reviewer
Request review from
Time tracking
Source branch: issue-956