Building a new type of testing framework
Nir Gazit
Posted on March 30, 2023
Hi Community!
Looking forward to hearing your thoughts on this.
Jest-opentelemetry was created out of a pain that @galklm and I felt when working on complex systems with multiple side effects, some of which happen asynchronously. People were changing the code of different services frequently, but weren't always aware of the dependencies across the system. So often, things would break - resulting in us up at 4am debugging the issue and reverting some recent deployments.
We were basically missing a way to make sure that all side effects always happen, even when we change the code of different microservices.
Most testing frameworks out there are testing the frontend but for some reason, only a few focus on backend and integration tests.
Validating side-effects with telemetry data
Enter OpenTelemetry. Don't worry if you're not familiar with it (although it's the 2nd largest CNCF project!) - it's just a standard protocol for reporting traces, logs and metrics from production services.
We realized it's a great way to observe all the side effects as they happen within the system. We can send a request to the system and then validate side-effects using the OpenTelemetry data coming out of the system.
We wanted to make it easy to validate any side effect. So you should be able to validate that an e-mail gets sent by writing:
expectTrace(t)
.toSendEmailWithSendGrid()
.withRecipient('someone@gmail.com')
.withBody('Your order is ready!')
Behind the scenes, this should look for a span (=part of a trace) with a POST request to SendGrid with the appropriate parameters.
Next Steps
We try to constantly add more high-level constructs so more side effects on systems (like Snowflake, Stripe, BigQuery, Segment, and others) can be tested.
What are your thoughts about the need for such a framework? Have you ever needed to write integration tests in that way? What would you expect to see here?
Feel free to comment here or at our Github page https://github.com/traceloop/jest-opentelemetry
Posted on March 30, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.