Skip to content
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

Merged
merged 1 commit into from
Jul 25, 2014

Conversation

kay
Copy link
Contributor

@kay kay commented Jul 15, 2014

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.

* @return true if the current JVM was started in debug mode, false
* otherwise.
*/
private boolean isDebugging(final List<String> arguments) {
Copy link
Member

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

Copy link
Contributor Author

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.

@kcooney
Copy link
Member

kcooney commented Jul 24, 2014

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?

@dsaff
Copy link
Member

dsaff commented Jul 24, 2014

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!).
@kay
Copy link
Contributor Author

kay commented Jul 24, 2014

Fixed typo, well spotted. Squashed branch history into 1 commit.

kcooney added a commit that referenced this pull request Jul 25, 2014
TestRule to disable specific other TestRules when debugging without modification to the test class
@kcooney kcooney merged commit c7d04da into junit-team:master Jul 25, 2014
@kcooney
Copy link
Member

kcooney commented Jul 25, 2014

Thanks!

@kcooney
Copy link
Member

kcooney commented Jul 27, 2014

Forgot to ask: would you please add this to the release notes?

@kay
Copy link
Contributor Author

kay commented Jul 27, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants