JRishi
JRishi

Reputation: 343

spring boot microservice end to end testing with cucumber and database verification

My project is based on event-driven microservice architecture. And We are trying to do end to end testing with cucumber, so that feature under test is available in a Business readable format.

Details are as below. Service Architecture:

There are 4 microservice involved. We send the request to Service A, and request gets processed and stored in DB, and Service A publish the event, which gets consumed by Service B, again Service B process the event and store the result in DB and publish the event to be consumed by Service C and like that Service D.

User(Post Request to Service A) Service A -> (Process, Store in DB and Publish event To Service B) -> Service b(Consume event from A, process and Store result in DB, publish an event to C)...

Testing Strategy: As part of the end to end testing, we will send the post request to Service A. and Service A will return only response 200 with no response Body.

We need to do verification of data in Each Service DB and assert that, it is as expected.

Something like feature file

Given The system is in the expected state. When Send Request to service A And Service returns 200 response And Verify Processed Data is present in Service A DB And Verify Processed Data is present in Service B DB And Verify Processed Data is present in Service C DB

**I want to understand, 1. what should be the right way to do this kind of testing.

  1. Is this the correct approach to do the end to end testing and verification in DB or some other approach should be used.**

Upvotes: 0

Views: 717

Answers (1)

Toerktumlare
Toerktumlare

Reputation: 14786

Here is your problem:

We need to do verification of data in Each Service DB and assert that, it is as expected.

This is done in unit tests and application tests.

If you need to verify that the data is correct in each database, then you are trying to do a unit test but your unit is a bunch of services combined.

You are doing a gigantic unit test.


Unit tests

unit tests verify that the logic in each service is correct

Application Test in isolation

Tests that the api responds with correct status codes for correct errors. That it reads and writes correctly to a database. Here you test the api of the application.

End to End

You stick a bunch of services together and you post some data, you verify that the data you get back is as expected. You don't go into in detail what each service has done, this is already been verified in earlier tests.

This is a final check that service basically can communicate and return what you expect. You have no interest in how they do it.


Your case

You post something to your service and you get a 200 back. Then you should be happy and the test passed. Because the service did what you expected, you posted something and it returned 200.

The earlier tests have passed (unit tests, application tests), and they tell you the story that each service is following the specification given. So when you are ready for an end to end you have already tested everything up to that point.

You only do end to end when everything is tested in isolation up to that point.

In an end to end test you have no interest at all in how it executes, you are only interested in what it returns.


Don't unit test in an end to end test

Upvotes: 1

Related Questions