In this use case, we want to validate the following story:
As a consumer
I want to choose a product from the catalog
And add it to my shopping cart
So I can continue to explore the catalog to fulfill my shopping list
You can trigger this use case by calling the endpoint
POST /api/cart from the Frontend service, with the following request body:
It should return a payload similar to this:
Building a Test for This Scenario
Using Tracetest, we can create a test that will execute an API call on
POST /api/cart and validate the following properties:
- The correct ProductID was sent to the Product Catalog API.
- The product persisted correctly on the shopping cart.
Running these tests for the first time will create an Observability trace like the image below, where you can see spans for the API calls (HTTP and gRPC) and database calls:
With this trace, now we can build assertions on Tracetest and validate the properties:
The correct ProductID was sent to the Product Catalog API.
The product persisted correctly on the shopping cart.
Now, you can validate this entire use case.
To replicate this entire test on Tracetest, you can replicate these steps on our Web UI or using our CLI, saving the following test definition as the file
test-definition.yml and later running:
tracetest run test -f test-definition.yml
We are assuming that the Frontend service is exposed on
name: Add product to the cart
description: Add a selected product to user shopping cart
- key: Content-Type
- selector: span[tracetest.span.type="http" name="hipstershop.CartService/AddItem"]
# checking if the correct ProductID was sent
- attr:app.product.id = "OLJCESPC7Z"
- selector: span[tracetest.span.type="database" name="HMSET" db.system="redis" db.redis.database_index="0"]
# checking if the product was persisted correctly on the shopping cart
- attr:tracetest.selected_spans.count >= 1