question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature] Add softly assertion support

See original GitHub issue

At 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:

  1. 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;
    }
}
  1. 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);
    }
}
  1. 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:open
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
lukas-krecancommented, Jun 18, 2020

Maybe the new AssertJ features like SoftAssertionsProvider might be the way

0reactions
akshayamaldhurecommented, Mar 7, 2022

@rkarczmarczyk Do you happen to know how to make the workaround for an assertion like this?

            assertThatJson(stringArray1)
                    .when(Option.IGNORING_ARRAY_ORDER)
                    .whenIgnoringPaths("[*].key1", "[*].key2")
                    .isArray()
                    .isEqualTo(stringArray2);

EDIT: I figured this out.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found