JGiven
JGiven copied to clipboard
JUnit 5: Find a good way to represent @Nested tests in the HTML report
JUnit 5 supports nested test classes with the @Nested
annotation. For JGiven this raises the question of how to represent that in the HTML report. Any ideas are welcome!
From this example, I could think of a drop-down-on-click functionality. One would have to count the inner tests as normal scenarios, which will show up in the global summary.
The readability will probably close to zero after two nested tests, that's why I'd propose hiding per default.
I am not sure I understood what you mean by drop-down-on-click functionality. In any case, the current design of JGiven does not really allow for hierarchical contexts. Neither in the JSON model nor in the HTML report.
@janschaefer - you already know that I'm fond of the hierarchic navigation on the lower left in the HTML5 report.
I would love the @Nested
classes to inherit the tags of the outer class.
When browsing the classes hierarchy the the nested classes should be below parent classes.
Regarding the first point: totally makes sense. Currently, it is not even possible to do otherwise ;-). Regarding the second point: I totally agree. That makes complete sense. The main question that I have is the case where you do something like described in the JUnit 5 documentation:
@DisplayName("A stack")
class TestingAStackDemo {
@Nested
@DisplayName("when new")
class WhenNew {
@Nested
@DisplayName("after pushing an element")
class AfterPushing {
@Test
@DisplayName("it is no longer empty")
void isNotEmpty() {
assertFalse(stack.isEmpty());
}
How should the text 'A stack - when new - after pushing an element' appear? It should not be in the navigation bar in the left, but somewhere next to the Scenario.
I see. Maybe start with concatenation?
I remember that Jasmine has a history of nesting tests. See the end of the page for the executed tests - https://jasmine.github.io/2.5/introduction
Jasmine shows the "describe" and "it" in a nested hierarchy. Maybe that's something to explore?
Class (aka "describe") names refine the scenario, The methods (aka "it") describe the test. I have an example on github, but there are better ones around.
I like the "when used with" in the Jasmine examples.
Yes. Concatenation will be definitely the first implementation. Maybe the hierarchy could be implemented similar to the grouping feature of the HTML report that is already implemented. It needs only be extended to support further nesting levels.