Harshana
Harshana

Reputation: 7647

Testing Spring Boot REST API

What would be the best practice to test a Spring Boot Rest API with JUnit? Using com.jayway.restassured.* api or org.springframework.boot.test.* api?

Any know advantage or drawbacks over another?

Upvotes: 2

Views: 1280

Answers (3)

Michael Desigaud
Michael Desigaud

Reputation: 2135

You can also use gherkin/cucumber to test your apis => https://github.com/RedFroggy/spring-cucumber-rest-api

Upvotes: 0

LHCHIN
LHCHIN

Reputation: 4009

If the version of Spring Boot you are using is later than 1.4.0 RC1, the module - spring-boot-test will be automatically added into your dependencies.

And Spring already comes with great support for writing integration tests leveraging the spring-boot-test module.

So I recommend you to just use the native API of Spring framework for testing.

Upvotes: 0

mzc
mzc

Reputation: 3355

Spring's test is faster as it doesn't need to spin-up a servlet container.

REST-Assured is slower, but it will test your application completely, including servlet container configuration (e.g. filter chain).

I prefer to use spring-test for unit-testing the controllers, and to do the complete functional regression test (using other tools) on a deployed version as the last step of my nightly build.

Upvotes: 1

Related Questions