Home > Enterprise >  How to test spring rest controllers while mocking third party APIs?
How to test spring rest controllers while mocking third party APIs?

Time:02-21

I want to write an integration test for a rest controller that calls third party apis. For mocking the third party api I am using mock-server java library and for integration tests I am using test containers. It seems both of these are clashing. Mock-server library requires the test case to be annotated with org.junit.test while test containers require the test case to be annotated with org.junit.jupiter.api.Test.

If I use the jupiter test annotation that start up fails with org.mockserver.client.SocketConnectionException: Unable to connect to socket /127.0.0.1:1080 while if I use the junit test annotation the test start up fails with Caused by: java.lang.IllegalStateException: Mapped port can only be obtained after the container is started

Has anyone come across this situation where you want to write rest controller tests along with mocking third party apis? Thanks.

CodePudding user response:

I could get my tests running by removing any annotations under the package org.junit. All annotations are from org.junit.jupitor.

  • Related