JUnit in this instance is a runner. This question is really about the difference between unit testing and integration testing, both of which can be implemented using JUnit as the surrounding execution framework.
There are many combinations of framework you could use. Some common ones:
- JUnit + mockito for unit testing - where your REST API controller beans are wired up to lightweight/mocked dependencies and you execute the API through JAVA
- JUnit + Cucumber + RESTAssured for integration testing - where you write a test fixture that expects to execute against a running server in order to exercise its API
There are points between these extremes too. You have to decide where your tests sit on the test pyramid. For highly permutational tests, you will want to write unit tests in order to be able to achieve the permutations easily and get speed of execution. If you're really trying to smoke test that your APIs are available, having already unit tested them, then you'll want to write a small number of integration tests.
In between the points of the spectrum there is a combination of mockito + the native test library of your service. For example, in Spring there's SpringTest and in Jersey there's the JerseyTest/Grizzly framwork. In these instances, a non-real http server is stood up to host your REST service and you test it by simulated REST calls to it, through the framework's client. This unit tests the HTTP marshalling layer as well as the first layer of REST controller code.
Answer from Ashley Frieze on Stack OverflowVideos
In my new job I need to automate API testing, so far I have only done UI automation with selenium. I am a bit lost on where to start now.
I need to automate API testing of microservices. The tech stack I will have to use is Rest Assured with Junit 5. The first task is to validate the json schema of the API under test.
Does anyone know of a tutorial series or simialr that explains the framework setup? I need guidance on project structure and especially in combination with the necessity of using Junit5.