LinhSaysHi
LinhSaysHi

Reputation: 642

Testing Spring Restful web services with jUnit

I am new to Spring and am overwhelmed with alot of the new terminology. What I am trying to accomplish is in a junit test, I want to test the result of a a get method in json form and compare it an expected result. Is this possible? And if so, how?

Upvotes: 1

Views: 935

Answers (1)

Tassos Bassoukos
Tassos Bassoukos

Reputation: 16142

You have two options:

  1. Unit test the controller. This isn't as useful as it sounds, as one "should" have minimal code (usually just validation) in the rest controller methods, and logic in services.
  2. Integration test your endpoints. This involves spinning up a full spring application and running tests against endpoints while having f.e. test data in the database. You can start your app from within maven in pre-integration-tests, and stop it in post-integration-tests.

Upvotes: 2

Related Questions