Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 544491

Summary: [JUnit 5] Result Comparison dialog not opened for nested MultipleFailuresError
Product: [Eclipse Project] JDT Reporter: Noopur Gupta <noopur_gupta>
Component: UIAssignee: Noopur Gupta <noopur_gupta>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, sam
Version: 4.11   
Target Milestone: 4.16 M3   
Hardware: All   
OS: All   
See Also: https://github.com/junit-team/junit5/issues/1781
https://git.eclipse.org/r/162872
https://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=cacfb4678d1cc82a49e03dbb5c7658a4d6df3d79
Whiteboard:
Bug Depends on:    
Bug Blocks: 543821    

Description Noopur Gupta CLA 2019-02-15 07:54:23 EST
@Test
    void dependentAssertions() {
        // Within a code block, if an assertion fails the
        // subsequent code in the same block will be skipped.
        assertAll("properties",
            () -> {
                String firstName = person.getFirstName();
                assertNotNull(firstName);

                // Executed only if the previous assertion is valid.
                assertAll("first name",
                    () -> assertTrue(firstName.startsWith("J")),
                    () -> assertTrue(firstName.endsWith("e"))
                );
            },
            () -> {
                // Grouped assertion, so processed independently
                // of results of first name assertions.
                String lastName = person.getLastName();
                assertNotNull(lastName);

                // Executed only if the previous assertion is valid.
                assertAll("last name",
                    () -> assertTrue(lastName.startsWith("D")),
                    () -> assertTrue(lastName.endsWith("e"))
                );
            }
        );
    }

- Example from JUnit 5 user guide. In 'Person' class, return lastName in getFirstName() and firstName in getLastName() so that the above example produces failures.

- Run the test. 

- In JUnit view, double-click on the first line in 'Failure Trace'.

=> 'Result Comparison' dialog is not opened.
Comment 1 Noopur Gupta CLA 2019-02-15 07:57:31 EST
(In reply to Noopur Gupta from comment #0) 
> - Example from JUnit 5 user guide. 
https://junit.org/junit5/docs/5.4.0/user-guide/index.html#writing-tests-assertions
Comment 2 Noopur Gupta CLA 2019-02-15 08:23:14 EST
On debugging this example, I see that the 'AssertionFailedError' present in the 'MultipleFailuresError' returns null for AssertionFailedError.getExpected() and AssertionFailedError.getActual(). The result is only present as a String in its 'Throwable.detailMessage' field.

I would expect that AssertionFailedError.getExpected() and AssertionFailedError.getActual() don't return null in this case so the corresponding values can be obtained.

Sam, can you please comment on this?
Comment 3 Sam Brannen CLA 2019-02-16 08:52:19 EST
The reason for this behavior is that the `assertTrue()` and `assertFalse()` methods in `org.junit.jupiter.api.Assertions` do not supply the actual and expected boolean values to the `org.opentest4j.AssertionFailedError` constructor.

I have raised the following issue to address this shortcoming in JUnit Jupiter.

https://github.com/junit-team/junit5/issues/1781

Please note, however, that the actual and expected values will always be absent in an `AssertionFailedError` if the failure comes from an invocation of `Assertions.fail(...)`.

Regards,

Sam
Comment 4 Sam Brannen CLA 2019-02-16 08:55:53 EST
Actually, there are other assertion failure scenarios for which the expected and actual values will be absent -- for example, `assertNotEquals()`, `assertNotSame()`, and others.

So you will need to defensively check for the presence of the expected and actual values in any case.
Comment 5 Noopur Gupta CLA 2019-02-18 00:21:40 EST
Thanks, Sam. I will look into it.
Comment 6 Eclipse Genie CLA 2020-05-12 07:12:54 EDT
New Gerrit change created: https://git.eclipse.org/r/162872
Comment 8 Noopur Gupta CLA 2020-05-19 04:39:59 EDT
Verified in I20200518-2220.