JGiven icon indicating copy to clipboard operation
JGiven copied to clipboard

JUnit 5: Find a good way to represent @Nested tests in the HTML report

Open janschaefer opened this issue 8 years ago • 6 comments

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!

janschaefer avatar Dec 26 '16 18:12 janschaefer

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.

cirquit avatar Dec 27 '16 14:12 cirquit

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 avatar Dec 27 '16 16:12 janschaefer

@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.

ahus1 avatar Jan 02 '17 20:01 ahus1

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.

janschaefer avatar Jan 02 '17 20:01 janschaefer

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.

ahus1 avatar Jan 02 '17 21:01 ahus1

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.

janschaefer avatar Jan 02 '17 21:01 janschaefer