[Feature] Add softly assertion support
See original GitHub issueAt this moment there is no easy way to collect Json asserts in bundle and evaluate it at the end of tests (to show all errors at one test iteration).
There is a way to create custom softly assert but it’s not very convenient. You have to do 3 steps:
- Create class that extends AbstractAssert
class JsonAssert extends AbstractAssert<JsonAssert, String> {
JsonAssert(String actual) {
super(actual, JsonAssert.class);
}
public static JsonAssert assertThat(String actual) {
return new JsonAssert(actual);
}
JsonAssert isEqualTo(String expected) {
assertThatJson(actual).isEqualTo(expected);
return this;
}
}
- Create proxy to already created class in class that extends JUnitSoftAssertions
public class CustomJUnitSoftAssertions extends JUnitSoftAssertions {
public JsonAssert assertThatJson(String actual) {
return proxy(JsonAssert.class, String.class, actual);
}
}
- Used new softly assert in test
public class SoftlyTest {
@Rule
public final CustomJUnitSoftAssertions softly = new CustomJUnitSoftAssertions();
@Test
public void test() {
String actualJson = "{}";
String expectedJson = "{}";
softly.assertThatJson(actualJson).isEqualTo(expectedJson);
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
How To Use Soft Assert In TestNG | TestNG Tutorial
Asserts are used to perform validations in the test scripts. There are two types of Assert: Hard Assert; Soft Assert.
Read more >SoftAssert in TestNG example - Selenium Easy
SoftAssert in TestNG helps to collect all the assertions throughout the @Test method. And to see assertions result at the end of the...
Read more >Soft Assertion with kotlin-power-assert | by Brian Norman
Soft assertions can help pin point all failures with a single test run. kotlin-power-assert can help diagram those failures and make them easier ......
Read more >How to use Assert and Verify in Selenium WebDriver
In the case of Soft Assert, the errors are accumulated in each @Test execution and the AssertAll() method throws asserts encountered during the ......
Read more >AssertJ / Fluent assertions for java
AssertJ Core features highlight · IDE configuration to get assertThat in code completion · Describe your assertion with as(String description, Object...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Maybe the new AssertJ features like
SoftAssertionsProvider
might be the way@rkarczmarczyk Do you happen to know how to make the workaround for an assertion like this?
EDIT: I figured this out.