Feature request: set breakpoint on assert fail
Feature request: set breakpoint on assert fail
Currently, when a Java assert fails, a stack trace is written to the terminal and the application ends. We know which assertion failed, but the application state is lost making it impossible to troubleshoot.
It would be nice to set this parameter in settings.json
"java.debug.breakOnAssertFail": true
Once this parameter has been implemented, when an assertion fails, the breakpoint pauses the application at the line where the assert failed, preserving the application state and allowing troubleshooting to proceed.
Eclipse has this feature; VSCode should too.
Thanks!
You can effectively achieve this, by setting a breakpoint in Assert.fail() where the AssertionError is thrown (in TestNG org.testng.Assert.fail(Assert.java:99) ) . Then you can go up the stack a few levels to your paused function.
Hi @loxcel, I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.
Suggestions
• Workaround: use an exception breakpoint on AssertionError to pause at the assert failure site:
- Open the Run and Debug view in VS Code.
- Under BREAKPOINTS, click the ➕ icon and select Add Java Exception Breakpoint.
- Enter java.lang.AssertionError and choose whether to break on caught/uncaught.
- Start debugging; the debugger will now stop exactly where the assertion is thrown, preserving state.
Other references with low confidence
Related feature-flag request
- Title: [Feature request] set feature flag to control this feature
• Suggestion to add feature flags in the Java pack extension; could serve as inspiration for adding
java.debug.breakOnAssertFail. • URL: https://github.com/microsoft/vscode-java-pack/issues/1481
The team will respond to your issue shortly. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or incorrect, please give it a 👎. Your feedback helps us improve!