When writing tests for the business layer, we recommend that you avoid using Spring Framework in the unit tests. This will ensure that your tests are framework independent and will run faster.
The following is an example of a unit test written without using Spring Framework:
@RunWith(MockitoJUnitRunner.class) public class BusinessServiceMockitoTest { private static final User DUMMY_USER = new User("dummy"); @Mock private DataService dataService; @InjectMocks private BusinessService service = new BusinessServiceImpl(); @Test public void testCalculateSum() { BDDMockito.given(dataService.retrieveData( Matchers.any(User.class))) .willReturn(Arrays.asList( new Data(10), new Data(15), new Data(25))); long sum = service.calculateSum(DUMMY_USER); ...