Writing BE tests #8
ctapobep
started this conversation in
Conventions & Approaches
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Test Pyramid
How not to write tests
In most projects there are 2 conflicting ideas:
Creating a Test Pyramid with Rich Model
Our approach is to build a Test Pyramid, follow the Rich Model (the logic isn't in Services, but in the domain model: Entity, Value Objects, etc) and almost never use mocks:
Also, to simplify and speed up our code a lot of logic is embedded in SQL, those for sure we need to test on DAO layer, and therefore the tests will be high level.
For more info read:
API Tests
We use RestAssured + MockMVC to test the API layer. For each API class we create a Client. Most methods of such Clients are of 2 types.
General purpose methods: they can be used to test unsuccessful scenarios, and so they can’t check the status code. Neither can they return the DTO that the endpoint usually returns - because oftentimes it’s the error that needs to be returned. Example:
But in most cases we want the happy path. So we also create happy path methods: invoke an endpoint and return a DTO or nothing at all. Such methods must check the response code.
Beta Was this translation helpful? Give feedback.
All reactions