Java JUnit 5 annotations differences

org.junit.Test is not in JUnit5, that class is being provided by your dependency on JUnit Vintage.

JUnit Vintage includes the JUnit Vintage test engine and classes such as org.junit.Test, this allows you to run JUnit4 tests alongside JUnit5 tests. It is a back compatability measure.

If you want to use only JUnit5 constructs (and leave JUnit4 out of your project) then just drop the dependency on JUnit Vintage and focus on org.junit.jupiter.api.Test.

If you need to run JUnit4 and JUnit5 tests side by side (perhaps for the duration of a migraiton / cut-over period) then retain the dependency on JUnit Vintage but write all new test cases using org.junit.jupiter.api.Test.

Update: in response to this …

I still don’t understand why org.junit.Test isn’t deprecated.

It simply does not exist in JUnit Jupiter (so deprecation is moot) and it is not deprecated in JUnit Vintage because it is a core element of JUnit Vintage. However, I think I can see where you are coming from; you upgraded to JUnit5 and – confusingly – org.junit.Test remains available on your classpath without @Deprecated so there is no clear indication of its ‘do not use‘ status. Perhaps you should think about whether you want/need any JUnit4 constructs supported when running JUnit5. If you do not need that then just do not include a dependency on JUnit Vintage and it’ll be like org.junit.Test never existed.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)