| Summary: | [JUnit 5] Result Comparison dialog not opened for nested MultipleFailuresError | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Noopur Gupta <noopur_gupta> |
| Component: | UI | Assignee: | 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 | ||
(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 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? 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 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. Thanks, Sam. I will look into it. New Gerrit change created: https://git.eclipse.org/r/162872 Gerrit change https://git.eclipse.org/r/162872 was merged to [master]. Commit: http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=cacfb4678d1cc82a49e03dbb5c7658a4d6df3d79 Verified in I20200518-2220. |
@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.