Search code examples
javatestingtestngintegration-testingweb-api-testing

How to Write test case for Rest Services with out using Server?


I am using TestNG to write test cases.

I want to write a test case for my Rest API, and my server is not up. It means no one is giving me a response.

I have URL which I can hit. I know the response also what should come as a response when I hit the URL.

It is possible using directly hit the API, fetch the response and then from the response fetch the body and check it whether it is true or not?

I don't want that way means my server is not.

Is this any way to mock the Rest Service and implement that?


Solution

  • There are numerous ways how to approach your issue. Whether they would be easy or complicated depends on what was the way your service under test was implemented.

    You can configure the required mock using Soap UI for example or WireMock. Unlike the previous ways you can build your mocks automatically if the developers used frameworks like Swagger (Swagger mock server) to describe the REST service.