-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TestRule to disable specific other TestRules when debugging without modification to the test class #956
Conversation
* @return true if the current JVM was started in debug mode, false | ||
* otherwise. | ||
*/ | ||
private boolean isDebugging(final List<String> arguments) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is used in a constructor, please make it static
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, didn't spot that.
Fantastic. One typo though. After you fix that, could you please squash commits? See https://github.com/junit-team/junit/wiki/Pull-Requests for instructions. @junit-team/junit-committers any objections to this change? |
Dig it. Looks great as an idea, and a shallow read-through of the code also looks fine. |
launched in debug mode. This feature is immediately useful with @Timeouts by disabling them during debugging allowing developers time to debug at their leisure without the test terminating abruptly. Timeouts or time sensitive logic in the code under test is not handled by this feature and may make this unuseful in some circumstances. The important benefit of this feature is that you can suspend rules without any making any modifications to your test class to remove them during debugging. Anecdotally removing timeouts for debug purposes often results in developers forgetting to restore them (including myself!).
Fixed typo, well spotted. Squashed branch history into 1 commit. |
TestRule to disable specific other TestRules when debugging without modification to the test class
Thanks! |
Forgot to ask: would you please add this to the release notes? |
This pull request is an alternative to #904. I prefer this change over #904 because it is cleaner code, it may be use for debugging problems beyond than of Timeout's, it's easier to test and maintain and it preserves backwards compatible in doing so.
This feature is immediately useful with @Timeouts by disabling them during debugging allowing developers time to debug at their leisure without the test terminating abruptly.
Timeouts or time sensitive logic in the code under test is not handled by this feature and may make this unuseful in some circumstances. Similarly any other uses are limited to behaviour within it's control.
The most attractive benefit of this feature is that you can suspend rules without any making any modifications to your test class to remove them during debugging. Anecdotally removing timeouts for debug purposes often results in developers forgetting to restore them (including myself!).
This feature somewhat relates to issue #738
The DisableOnDebug rule exposes an isDebugging() method accessible to tests. I saw no harm in doing this and thought there might be some interesting uses with the Assume feature or disabling other code paths that cannot easily be debugged. e.g. above I alluded to time sensitive logic in user code that we can't control, isDebugging() may be combined with user code to manage that.
I've tried to keep as close to the JUnit projects conventions but please let me know if there is anything you'd prefer to be changed.