Tech Radar

EDITION

Microservices: Prefer API tests for BDD

Techniques · Adopt· Trending up

In Skai, our microservice templates contain infrastructure for creating two types of behavioral tests - API tests (using Karate) and in-process integration tests (using Cucumber). We should opt for an API test for microservices whose primary interfaces are RESTful.

The benefits of API tests over Cucumber tests outweigh their downsides: they cover more functionality (e.g., HTTP statuses) with little-to-no extra effort; They provide an excellent source of documentation (thanks to Karate's syntax); They test the application in complete isolation, closest to production. And they can easily be reused as Smoke tests in staging and production when relevant. One should fall back to using Cucumber only in the rare cases where API tests are insufficient, e.g., when a component of the application must be replaced with a stub or when necessary test data can't be populated via an API call.