Mockito is now included in core as of openmrs 1.9.0. See
TRUNK-2586. All unit tests go down and hit the database. This makes them more like functional tests. (Or, precisely speaking, "Component Tests".) To make the tests run 10x faster we need to be using mocks.
We need to start by demonstrating a good example of this, and we'd like to focus on some tests that take a particularly long time to run...
For a few examples (see below):
- rename the existing test class to end with "IT" (for integration test) instead of "Test". The idea is that we want to keep the existing test around, since we have it, and run it in CI, but not during the regular build. (See
- write new tests in a new test class (ending with Test, i.e. the original name of the class you renamed to IT in the prior step.)
- the new tests should not extend ContextSensitiveTest, and use mocks instead
- bring what you just did back to a design call, and we'll decide whether this was the right approach to apply "everywhere" or we need further tweaks
Examples to start with:
Doing this will probably require using PowerMock to deal with the fact that the code you're testing makes static calls to things like Context.getAuthenticatedUser(), Context.getXyzService(), etc. To get around this, you need to use the @RunWith(PowerMockRunner.class) and @PrepareForTest(Context.class) annotations, and PowerMockito.mockStatic as you can see in these two examples:
Another sample implementation (though this is older than the examples above) is in the last email in this thread: http://listarchives.openmrs.org/Context-class-td5471380.html