Coffee-Driven Development

Brewing Thoughts for Better Code and Stronger Teams
en nl

Testing GraphQL with Specifications: A Deep Dive with Reqnroll

2025-01-28 Testing

GraphQL has been around since 2012, yet many developers haven’t had the chance to work with it. Personally, I’ve been using GraphQL on and off for several years, both in personal and professional projects. Recently, I’ve been diving deeper into it again—and I’ve fallen in love with it all over.

While implementing a few queries and mutations, I started to wonder: how could I effectively test my GraphQL implementation? Specifically, how could I send queries and mutations with a GraphQL client directly from my tests to ensure everything works as expected?

After some experimentation, I found a solution I’m excited to share: combining specifications with Reqnroll, the .NET WebApplicationFactory, and the Strawberry Shake GraphQL client to test a Hot Chocolate GraphQL server. This approach not only works seamlessly but also results in clean, readable specifications.

In this article, I’ll guide you through the process of setting up these tests, allowing you to test your own GraphQL server with clarity and confidence. Let’s get started!

Continue reading

Specflow and Eventual Consistency

2021-05-30 Testing

SpecFlow is a tool which can be used to describe test scenarios and automate the tests. Although I have been using SpecFlow for a while now I never used it for advanced examples where time might be an issue. Lets show a simple example scenario first. A scenario, written in Gherkin, looks like this:

Scenario: Add simple item with due date
    Given the user enters "wash my car"
    And the user adds a due date of "1-1-2022"
    When the user saves the item
    Then the item "wash my car" is added to the list
    And the due date is "1-1-2022"

This scenario is easy to implement, the item will be added and stored. That’s it. Easy to verify, no delays, straight forward. But what if you have some microservices with a queueing mechanism? A scenario where data will be queued before processing so we can’t exactly know when the data is processed?

Continue reading