vscode-java-debug icon indicating copy to clipboard operation
vscode-java-debug copied to clipboard

Feature request: set breakpoint on assert fail

Open loxcel opened this issue 5 years ago • 2 comments

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!

loxcel avatar May 02 '20 20:05 loxcel

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.

scipilot avatar Jul 17 '21 07:07 scipilot

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:

  1. Open the Run and Debug view in VS Code.
  2. Under BREAKPOINTS, click the ➕ icon and select Add Java Exception Breakpoint.
  3. Enter java.lang.AssertionError and choose whether to break on caught/uncaught.
  4. 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!

github-actions[bot] avatar Nov 11 '25 11:11 github-actions[bot]