Nicer way to support soft assertions (Expect.create junit4 Rule) in JUnit5?
See original GitHub issueFrom a purely JUnit5 perspective, am I missing something?
I made this wrapper around the core Expect function:
    public class ThingyThing {
        public static void softly(final SoftAssertions softly) throws Throwable {
            Expect expect = Expect.create();
            expect.apply(new Statement() {
                @Override
                public void evaluate() throws Throwable {
                        softly.apply(expect);
                }
            }, Description.EMPTY)
                    .evaluate();
        }
        public interface SoftAssertions{
            void apply(final Expect expect);
        }
    }
Used like:
        ThingyThing.softly(expector -> {
            expector.that(1).isEqualTo(2);
            expector.that(-1).isGreaterThan(0);
        });
Outputs:
2 expectations failed:
  1. expected: 2
     but was : 1
     	at io.<snip>.ThingTest.lambda$testRemit$0(ThingTest.java:113)
     
  2. expected to be greater than: 0
     but was                    : -1
     	at io.<snip>.ThingTest.lambda$testRemit$0(ThingTest.java:114)
P.s. amazing framework BTW - beautiful. Especially for chained custom objects. Amazing. Wish I’d found it sooner.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
 Top Results From Across the Web
Top Results From Across the Web
Assertions in JUnit 4 and JUnit 5 - Baeldung
Assertions are utility methods to support asserting conditions in tests; these methods are accessible through the Assert class, in JUnit 4, ...
Read more >Is there ErrorCollector rule analogue for JUnit5 - Stack Overflow
For now I see that the best way is to use assert-j like this @ExtendWith(SoftAssertionsExtension.class) public class ...
Read more >Writing Assertions With JUnit 5 Assertion API - Petri Kainulainen
This blog post describes how you can write assertions by using the JUnit 5 assertion API.
Read more >Migrating From JUnit 4 to JUnit 5: A Definitive Guide
Methods for asserting reside in the org.junit.jupiter.api.Assertions class instead of org.junit.Assert class. In most cases, we can just find ...
Read more >JUnit5 Assertion Migration Strategy - EvilTester.com
The main differences between JUnit4 and JUnit5 seem to be: annotations, rules, and assertions. ... But assertions have the issue that in JUnit5...
Read more > Top Related Medium Post
Top Related Medium Post
No results found
 Top Related StackOverflow Question
Top Related StackOverflow Question
No results found
 Troubleshoot Live Code
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free Top Related Reddit Thread
Top Related Reddit Thread
No results found
 Top Related Hackernoon Post
Top Related Hackernoon Post
No results found
 Top Related Tweet
Top Related Tweet
No results found
 Top Related Dev.to Post
Top Related Dev.to Post
No results found
 Top Related Hashnode Post
Top Related Hashnode Post
No results found

My solution Inspired by
ThingyThing.A.
B.
I look forward to any form of Expect Extension for JUnit5 being added in the future!
As belatedly noted on #894, anything that we label as P3 has no timeline for being reviewed 😦 We hope to eventually schedule some more time for Truth (especially for features that could work well in Kotlin, like this one), but there are no plans yet.
(Another thing we should do: Figure out if this feature request and https://github.com/google/truth/issues/266 represent different requests or if they could be merged.)