JMock assertIsSisfisfied in TearDown?

I don't know why, but I always wrote my JMock tests as follows:

@Test public void testMyThing() throws Exception { mockery.checking(new Expectations() {{ oneOf(mockObj).foo(); }}); testObj.bar(); // calls mockObj.foo() mockery.assertIsSatisfied(); } 

But when there are many tests, is it better to move assertIsSatisfied to a breakdown?

 @After public void tearDown() throws Exception { mockery.assertIsSatisfied(); } 
+6
source share
2 answers

The recommended way to do this is to use the JMock runner. Annotate a class using

 @RunWith(JMock.class) public class TestClass { 

This will trigger approval at the right place in the testing life cycle. Teardown is the wrong place, because a failure may not be reported correctly and may ruin another cleanup.

We also have a mockery rule in the repository that works with the new @Rule framework.

+5
source

Yes, I try to do it in disruption. He keeps the focus of individual testing methods on what they actually test by deleting the template in @After - for me it is important that the tests are as expressive and readable as possible.

In fact, I sometimes take it further, and use the base class JMockSupport , which handles Mockery for me (and also provides convenient implementations of mock(...) ). Of course, this is just convenience and not a requirement at all, as in JUnit 3.

0
source

Source: https://habr.com/ru/post/892322/


All Articles