The current https://junit.org/junit5/docs/current/user-guide uses the term container around 50 times without defining it.
What is the difference between test class and container? Can one container be in more than one class? Can one class has more than one container? (for example nested classes).
Let me chime in as one of the original members of the JUnit 5 team...
JUnit 5, as a platform, allows deeply nested trees of containers and tests. You can even have nodes that are both a test (= it makes sense to run it individually) and a container (= it has children). At the root of any testengine‘s Test tree is always the engine container. There’s one important thing to know: Containers without children that are not themselves also tests will be pruned and not run!
As for Jupiter you have classes and nested classes as containers and test methods as tests. Consider the case of dynamic tests, though, where the annotated method is a test, I think, but it also creates a lot of children which are themselves tests. So it’s also a container.
Other test engines might decide to create containers for the packages and parent packages as well.
I suppose that container here is something containing tests :))
If you debug an executionStarted
method in any listener you will see that top level container called "[engine:junit-jupiter]" (for the standard runner, or any other engine name you're using).
Then you'll see a test classes (each of them is container). If you're using "nested" (I mean @Nested
tests) feature, your upper level tests will be also shown as container.
You can add more levels by creating your own engine and overriding test discovery mechanism.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With