borachio icon indicating copy to clipboard operation
borachio copied to clipboard

Borachio should not require 'withExpectations'

Open alexnixon opened this issue 13 years ago • 1 comments

Under JUnit 3, almost all Borachio-enabled tests will take the form:

@Test // or @MediumTest and friends if using RoboGuice
def someTest {
    withExpectations {
        // set expectations
        // run test code
   }
}

It would be convenient if Borachio called resetExpectations and verifyExpectations automatically at the start and end of any methods annotated as tests.

alexnixon avatar Sep 26 '11 17:09 alexnixon

You can avoid the use of withExpectations by overriding setUp and tearDown as described here in the documentation:

setUp and tearDown

This is not the recommended approach, because JUnit calls tearDown even if a test fails, and exceptions in tearDown override exceptions thrown by the test. This will result in the original cause of the failure being masked.

override def setUp() {
  resetExpectations
}

override def tearDown() {
  verifyExpectations
}

def testSomething {
  // Setup expectations
  // Exercise code under test
}

But as that says, there are issues with it :-(

I'm not sure how I could make use of the @MediumTest etc annotations (which are an Android, not a JUnit3, thing). If you have any suggestions, I'd be delighted to hear them. There's no such thing (AFAIK) as a @Test annotation on Android, is there? That's JUnit4 (which isn't supported on Android). Or am I missing something?

paulbutcher avatar Sep 27 '11 09:09 paulbutcher