2

Whenever I create an assertion, Eclipse suggests me to import it from one of these two packages.

For example, when I tried to compare arrays with assertArrayEquals() Eclipse suggested importing it from either

org.junit.Assert.assertArrayEquals
 or 
org.junit.jupiter.api.Assertions.assertArrayEquals

both methods work perfectly. is there any fundamental difference between these two?

NoamV
  • 65
  • 5
  • 1
    Does this answer your question? [Java JUnit 5 annotations differences](https://stackoverflow.com/questions/48853312/java-junit-5-annotations-differences) – Progman Jan 20 '21 at 21:14

1 Answers1

5

It’s historical more than anything else. The org.junit package was first and had a mixture of the API and implementation classes for running the tests and test cases.

For the JUnit 5 api, the classes were split across different packages, so that when you have the annotations they can be included separately for your runtime and the test execution engine is in a different package.

To make things easy, the classes kept their same names so you just needed to change the package included on the class path.

So you can use either, but try and use one package consistently.

The other observation is that the reason for keeping the packages separate is so hat you could have a project which consisted of some old JUnit libraries, and some new libraries. So you wouldn't need to refactor everything in one go to migrate.

https://junit.org/junit5/docs/current/user-guide/#migrating-from-junit4

PS if you want to ignore the older JUnit packages you can add them to the step filters in Eclipse's preferences, and then Eclipse won’t suggest that package.

AlBlue
  • 23,254
  • 14
  • 71
  • 91