This isn't a unit test though. This is an implementation test, as you are acutally including API calls. A unit test would simply be testing the method on it's own, without using a restful API. Ideally, one should have both unit and integration tests; after all, the unit test might pass as your method works as expected but your integration test might fail due to the path having changed - or an issue the other way around might arise.
I actually agree with this and I've wrote unit test using just the method. I like both ways and the tooling is great in Java to just make the API call like this.
Hi I recently migrated to springboot 3.1.5. When I am modifying my existing test cases the way you have explained, I am getting Failed to load application context. Any suggestions? Thanks
difficult to say but most likely conflicting dependencies. You might need to look into making sure dependencies are compatible with your version of spring boot
you can mock the dependencies as well. for example, in your test file, you can write import org.springframework.boot.test.mock.mockito.MockBean; @MockBean MyService myService;