junit-team/junit — pull request #956 by kay (2014-07-15 19:43:48+00:00)
Title: TestRule to disable specific other TestRules when debugging without modification to the test class

This pull request is an alternative to https://github.com/junit-team/junit/pull/904. I prefer this change over https://github.com/junit-team/junit/pull/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 https://github.com/junit-team/junit/issues/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.