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.

JUnit 5 Assert Equals Comparison Failure In IntelliJ Is Not Displayed

See original GitHub issue

Hi

I am using AssertJ variant on latest version of JsonUnit in IntelliJ 2021.3.3, Java 11:

dependencies {
    testImplementation 'net.javacrumbs.json-unit:json-unit-assertj:2.33.0'
    testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'
}

This test with a jsonunit assertion does not display the IntelliJ assert equals comparison failure:

@Test
void jsonUnitShouldProvideIntelliJFailureDiff() {
    assertThatJson("{\"foo\":1, \"bar\":2}").isEqualTo("{\"b\":3, \"a\":1}");
}

Output:

JSON documents are different:
Different keys found in node "", missing: "a","b", extra: "bar","foo", expected: <{"a":1,"b":3}> but was: <{"bar":2,"foo":1}>

org.opentest4j.AssertionFailedError: JSON documents are different:
Different keys found in node "", missing: "a","b", extra: "bar","foo", expected: <{"a":1,"b":3}> but was: <{"bar":2,"foo":1}>

But this junit assertion does:

@Test
void junitShouldProvideIntelliJFailureDiff() {
    assertEquals("{\"foo\":1, \"bar\":2}", "{\"b\":3, \"a\":1}");
}

Output:

expected: <{"foo":1, "bar":2}> but was: <{"b":3, "a":1}>
Expected :{"foo":1, "bar":2}
Actual   :{"b":3, "a":1}
<Click to see difference>

We’d really like to have the comparison failure (available by clicking the <Click to see difference> link in test output) in the IDE as it helps triage the failures with better context for larger json objects.

Is there any way to achieve this?

Ideally it would be great to have both the jsonunit error, which is more descriptive than the junit equivalent, and the link the IntelliJ comparison failure.

Thanks!

Ben

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ljchen1commented, Apr 26, 2022

Hi, it should be a issue in the IDEA instead of the JsonUnit. The related issue is here: https://youtrack.jetbrains.com/issue/IDEA-277216/<Click-to-see-difference>-is-not-present-in-test-output-when-run The JsonUnit use the assertj under the hood so it has this issue too.

0reactions
lukas-krecancommented, Apr 26, 2022

Makes sense, thanks a lot for investigation

Read more comments on GitHub >

github_iconTop Results From Across the Web

Test "Comparison Failure" dialog converts escaped line ...
When running a JUnit 5 test with the Gradle test runner the "Comparison Failure" dialog for failed assertions converts the escaped line break...
Read more >
JUnit saying test failed. See difference say content is identical
You want assertEquals; assertSame if they are the same object. ... It will not show you the difference between '\n' and '\n' -...
Read more >
IntelliJ outputs error messages twice · Issue #680 · google/truth
I am working on IntelliJ 2019.3, with Truth 1.0 and Java 11.0.6, ... here's the behavior of Junit5, which does not raise ComparisonFailure:....
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 >
How to use Assert and Verify in Selenium WebDriver
Soft Asserts are not included by default in the TestNG framework. You have to include the package org.testng.asserts.Softassert when soft assert ...
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