google / google/truth

JUnit5 support for the existing soft-assertions support (Expect.create JUnit4 Rule)

Open
#893 5 comments 1 reaction 0 assignees View on GitHub
P3 type=addition
Dominant language
Java
Stars
2.8k
Forks
275
Avg merge
7m
Merged PRs (30d)
4

Description

From 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..ThingTest.lambda$testRemit$0(ThingTest.java:113)

2. expected to be greater than: 0
but was : -1
at io..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.

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.