assertj / assertj/assertj

SoftAssertion implementation that generates dynamic tests

Open
#2,674 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2.8k
Forks
788
Avg merge
14h 57m
Merged PRs (30d)
36

Description

#### Feature summary

I love soft assertions.

One problem with soft assertions, for complex tests, is that it can be hard to navigate the error message to find the errors that you're interested in - especially if the individual failures themselves consist of several lines of failure message.

What I am proposing: instead of combining the failures into a single MultipleFailuresError which is reported against a single test node by Jupiter, use Jupiter's DynamicTestNode extension to implement each soft assertion failure in its own test node. Users then get a visible, summary of the failures in the JUnit test tree (displayed by most IDEs), can navigate direct to the failure that they are interested in and click on it to see the failure message that is relevant for that specific test failure.

An initial implementation would be a soft proxy implementation that can be called upon to dynamically generate a stream of `DynamicTest` nodes that can be returned by a `@TestFactory` method. But adopting this would not be seamless for existing soft assertion tests, as each `@Test` method would need to be refactored into a `@TestFactory` method for this to work.

But ideally, the implementation would be API compatible with the existing `SoftAssertionsExtension` and would not require such a drastic re-write of all tests - it would only be the way that failures are reported that changes. That way, all you need to do is change which extension you are using to implement your soft assertions. I think that this is eminently achievable. An implementation with a relatively seamless adoption pathway is possible, but would first require an enhancement to Jupiter so that an extension could register a dynamic test during test execution. See junit-team/junit5#1444 for the relevant issue.

*Edit: missed a crucial "not" when I originally wrote this post which accidentally inverted the meaning.*

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.