At the beginning of the project, I created several tests using only Mockito. Now, I started to create the first endpoint test of the project, using MockMvc and, therefore, many tests failed. It seems that the context introduced by this integration test changed the result of several tests that were isolated.
The biggest problem is that if I "correct" the tests with the new results and run all the tests together, everything works fine. However, when I run tests singly, they fail, because the results are back to what they were before the "correction".
In short, I need to prevent tests with MockMvc from interfering with unit tests.
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class MyEnpointsControllerTest {
// my tests
}
@RunWith(MockitoJUnitRunner.Silent.class)
public class MySingleImplementationTest {
// my tests
}
Example of what is going on: When a I run the tests of a file, there is a static variable in somewhere, called
messageSourcethat isnull. But when I run all tests, MockMvc part starts the application which gives some value tomessageSource. That's why my unit tests can have 2 results depending on the situation.