What's the purpose of the JUnit 5 @Nested annotation

sab picture sab · Mar 25, 2016 · Viewed 7.6k times · Source

In JUnit 5, there is a new annotation: @Nested.

I understand how it work, I understand why we use nested class, I just don't understand why we need to have nested test class in our test.

Answer

Mureinik picture Mureinik · Mar 25, 2016

The @Nested annotation allows you to have an inner class that's essentially a test class, allowing you to group several test classes under the same parent (with the same initialization).