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.

`satisfies()` with nested assertions obscures stack trace

See original GitHub issue

Summary

satisfies() with nested assertions obscures stack trace

Example

We have a satisfies() call with many embedded assertions like this. AssertJ doesn’t expose the stack trace of the actual line that triggered the assertion in this case, only the satisfies() line:

assertThat( tsdbDeviceMediator.getDeviceSnapshots( 1 ) )
        .singleElement()
        .satisfies( tsdbDevice -> {
            assertThat( tsdbDevice.getRevision() ).isEqualTo( 1 );
            assertThat( tsdbDevice.getPlatform() ).isEqualTo( "IOS" );
            assertThat( tsdbDevice.getProfile() ).isEqualTo( "ios" );
            assertThat( tsdbDevice.getProfileOverrides() ).isEqualTo( "IOS" );
            assertThat( tsdbDevice.getModel() ).isEqualTo( "IOS" );
            assertThat( tsdbDevice.getFirmwareVersion() ).isEqualTo( "IOS" );
            assertThat( tsdbDevice.getSerialNumber() ).isEqualTo( "IOS" );
            assertThat( tsdbDevice.isDynamicIpAddress() ).isEqualTo( "IOS" );
            assertThat( tsdbDevice.getIpAddress() ).isEqualTo( "IOS" );
            assertThat( tsdbDevice.getMacAddress() ).isEqualTo( "IOS" );
            assertThat( tsdbDevice.getSecondaryMacAddress() ).isEqualTo( "IOS" );
            assertThat( tsdbDevice.getAlias() ).isEqualTo( "IOS" );
            assertThat( tsdbDevice.getTvModelId() ).isEqualTo( "IOS" );
            assertThat( tsdbDevice.getDisplayMode() ).isEqualTo( "IOS" );
            assertThat( tsdbDevice.getSkinResolution() ).isEqualTo( "IOS" );
            assertThat( tsdbDevice.getMaxAgeRating() ).isEqualTo( "IOS" );
            assertThat( tsdbDevice.isTombstone() ).isFalse();
        } );

Here’s what it looks like when I run this in IntelliJ. Line 222 is highlighted in the stack trace, but not the actual exception-triggering line:

image

Interestingly enough, if I wrap this in a try/catch like below and rethrow it as a RuntimeException, it starts working much better:

assertThat( tsdbDeviceMediator.getDeviceSnapshots( 1 ) )
        .singleElement()
        .satisfies( tsdbDevice -> {
            try {
                assertThat( tsdbDevice.getRevision() ).isEqualTo( 1 );
                assertThat( tsdbDevice.getPlatform() ).isEqualTo( "IOS" );
                assertThat( tsdbDevice.getProfile() ).isEqualTo( "ios" );
                assertThat( tsdbDevice.getProfileOverrides() ).isEqualTo( "IOS" );
                assertThat( tsdbDevice.getModel() ).isEqualTo( "IOS" );
                assertThat( tsdbDevice.getFirmwareVersion() ).isEqualTo( "IOS" );
                assertThat( tsdbDevice.getSerialNumber() ).isEqualTo( "IOS" );
                assertThat( tsdbDevice.isDynamicIpAddress() ).isEqualTo( "IOS" );
                assertThat( tsdbDevice.getIpAddress() ).isEqualTo( "IOS" );
                assertThat( tsdbDevice.getMacAddress() ).isEqualTo( "IOS" );
                assertThat( tsdbDevice.getSecondaryMacAddress() ).isEqualTo( "IOS" );
                assertThat( tsdbDevice.getAlias() ).isEqualTo( "IOS" );
                assertThat( tsdbDevice.getTvModelId() ).isEqualTo( "IOS" );
                assertThat( tsdbDevice.getDisplayMode() ).isEqualTo( "IOS" );
                assertThat( tsdbDevice.getSkinResolution() ).isEqualTo( "IOS" );
                assertThat( tsdbDevice.getMaxAgeRating() ).isEqualTo( "IOS" );
                assertThat( tsdbDevice.isTombstone() ).isFalse();
            }
            catch ( Throwable t ) {
                throw new RuntimeException( t );
            }
        } );

Line 227 is properly listed in the stack trace, making it much easier to debug the actual cause of the problem:

image

Conclusion

Could this be a bug in IntellIJ or AssertJ? 🤔 I tried playing with Assertions.setRemoveAssertJRelatedElementsFromStackTrace(false) but it didn’t seem to affect this.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
joel-costigliolacommented, Apr 13, 2022

we aim to release 3.23.0 at the end of month but in software development there are “sometimes” delays 😄 .

1reaction
joel-costigliolacommented, Mar 26, 2022

@perlun I’m closing this issue in favor of https://github.com/assertj/assertj-core/issues/2067 but feel free to continue commenting on it if you feel this is not the best solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

satisfies() with nested assertions obscures stack trace #2542
Summary satisfies() with nested assertions obscures stack trace Example We have a satisfies() call with many embedded assertions like this.
Read more >
Assertions (and on not sweeping things under the rug)
When an assertion fails, only the text of the assertion (e.g., “x > 0”) and its location in the source code is printed...
Read more >
Ginkgo test suite - GitHub Pages
Ginkgo is a testing framework for Go designed to help you write expressive tests. It is best paired with the Gomega matcher library....
Read more >
How to get the stack trace of a nested exeption in python?
If an exception is raised I'd like to analyse the stack trace in python that tells about where exactly the problem is in...
Read more >
docs/gmock_cook_book.md · master · google / googletest
The With() clause allows us to match all arguments of a mock function as a whole. For example,. using ::testing::_; using ...
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