Running nested JUnit tests

John Hendrikx hjohn at xs4all.nl
Fri Sep 17 10:33:41 UTC 2021


I would like to provide some junit tests in a PR.

These are written in a nested style for easy readability. For example:

     private StringProperty property = new SimpleStringProperty("A");

     @Nested
     class When_map_Called {

         @Nested
         class WithNull {

             @Test
             void shouldThrowNullPointerException() {
                 assertThrows(NullPointerException.class, () -> 
property.map(null));
             }
         }

         @Nested
         class WithNotNullReturns_ObservableValue_Which {
             private ObservableValue<String> observableValue =
                property.map(v -> v + "Z");

             @Test
             void shouldNotBeNull() {
                 assertNotNull(observableValue);
             }

             // etc...
         }

         // etc..
     }


Can this PR either:

1) Add JUnit 5 as a dependency

2) Use a custom JUnit 4 runner as a dependency that provides nested 
functionality

3) Add our own Nested runner based on an Apache 2.0 licensed one (about 
200 lines of test code).

For point 2 and 3, there is a good one here: 
https://github.com/NitorCreations/CoreComponents/tree/master/junit-runners)

Please let me know, I think tests are very important and having to tools 
to write them as readable as possible would be great.

--John





More information about the openjfx-dev mailing list