I'm learning Mockito. Before starting to use mock objects I had some Unit tests that were more like integration tests, so I'd have a test class with a setUpBeforeClass() like this:
@BeforeClass
public static void setUpBeforeClass() throws Exception {
instance = new UserDataAccess();
instance.setDb(new MyDb());
}
Now with the mock Object is a lot similar, but the setup is slightly more complicated:
@BeforeClass
public static void setupBeforeClass throws Exception {
instance = new UserDataAccess();
MyDb myDb = mock(MyDb.class);
when(...).thenReturn(...);
...
instance.setDb(myDb);
}
Also I've a test suite that used to load the DB in a well known state before running the tests, and this is done with the first test class called by the suite.
What I'm thinking is that I should not throw away the integration tests, so I was considering to split the test suite into a UnitTestSuite and a IntegrationTestSuite. In fact the mock tests, are not testing everything, for instance they don't test if queries are correct.
Also, the only difference between those two suites, will be the initial DB reset and the setUpBeforeClass() code. It would be a waste to copy and change all the test classes just to change a method. The initial DB reset is easy to skip, I just not include the db reset test class in the Unit test suite.
To split unit and integration tests what do you suggest? Extending all the original classes to override the static method and then including the right class in the suite?
Or other approaches? How are you doing it, or what would you do?