I have a test for MyController.java
@WebMvcTest(controllers = MyController.class)
class MyControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private SomeService service; //dependency of MyService
@SpyBean
private MyService myService; //used in MyController
@Test
void testMyControllerCall() {
//someTest
}
}
If I annotate MyService with @SpyBean, it will call the real service and inject the bean in MyController, but my problem is that when I run coverage for MyControllerTest, it will not mark MyService as covered with tests, so I want a regular (Not mock or spy) implementation of MyService and inject it to MyController in the test class, but I don't know how.
If I put MyControllerTest outside test/java/controller package, it will mark MyService with coverage, but I don't want that fix as I want MyControllerTest to be in that package to be organized.
My folder structure is like this,
> main/java
> --/controller
> ----/MyController.java
> --/service
> ----/MyService.java
> test/java
> --/controller
> ----/MyControllerTest.java