In every book is written that unit test should in the assert/verify section check only one thing. And in the same time ther is a example like this below
@Test
public void shouldReturnSomethingAndExecuteExternalComponent(){
// Given
ExternalComponent externalComponent = EasyMock.createStrictMock(ExternalComponent.class);
configureMock(externalComponent);
// When
Result result = objectUnderTest.foo();
//Then
Result expectedResult = ...
Assert.assertEquals(expectedResult, result);
externalComponent.verify();
}
In this case, behavior is checked (executing of externalComponent – externalComponent.verify()) and the state of the object after the test(“assertEquals(expectedResult, result)“). Is it clean that two verifications are mixed in one test? what do you think? Or it should be splitted on two test ?
The test should be split into two tests
If you use Mockito instead of EasyMock then the shouldExecuteSomething will look nicer, because you don’t have to define the verified behaviour of the external component before executing the test.