Article ยท January 4, 2025

๐Ÿง‘โ€๐Ÿ’ป Why Should Developers Automate? ๐Ÿค–

Explore why automation is key for modern developers. From validating HTTP endpoints to testing event-driven architectures, learn how automation saves time, reduces risk, and ensures consistency in your microservices.

dotnet-coreqaautomationtestingunit-testingfunctional-testingmicroservicesevent-drivenclean architecture
Mauro GiobertiTech Lead ยท technical writer ยท speakerProfessional profile โ†’
๐Ÿง‘โ€๐Ÿ’ป Why Should Developers Automate? ๐Ÿค– article artwork

We run unit, integration, and functional tests, yet bugs still pop up in our apps! ๐Ÿชฒ I'm here to show you a fun solution for those pesky QA tickets that bounce back to dev and even those sneaky bugs that make it to production ๐Ÿ˜….

This is key to speeding things up โšก, guaranteeing quality, and most importantly, saving money ๐Ÿ’ธ. A simple automation that takes less than an hour can save us tons of headaches ๐Ÿคฏ and catch bugs way earlier! ๐Ÿ†

๐Ÿ‘‰ Here are three key areas where automation can make a huge difference:

โœ… Automating HTTP Status Validations

HTTP verbs like GET, POST, PUT, PATCH, DELETE are the backbone of APIs. Automating tests for HTTP responses (e.g., 200, 201, 204, 400, 404) makes sure every endpoint behaves the way we expect. ๐Ÿš€

Here's an example of validating a POST response:

[Fact]
public async Task Given_Valid_Request_When_Post_Then_Return_Created()
{
    var postPayload = new AppointmentPostBody("New Appointment", DateTime.UtcNow, DateTime.UtcNow.AddHours(1), "Description");
    var request = RequestHelper.PostRequest(Url.Appointments.Post, postPayload);

    var response = await Client.ExecuteAsync<AppointmentResponse>(request);

    Assert.Equal(HttpStatusCode.Created, response.StatusCode);
    Assert.NotNull(response.Data);
    Assert.Equal("New Appointment", response.Data.Title);
}

โœ… Automating Event Handling Validations

Modern microservices often rely on event-driven architectures. Automating these checks ensures listeners process events as expected. For instance, when an AppointmentNotificationEvent is published, the listener updates the database with the right data. โš™๏ธ

[Fact]
public async Task Given_Valid_Notification_Event_When_Handled_Then_Entity_Is_Updated()
{
    var eventPayload = new AppointmentNotificationEvent("600-notification", "AppointmentNotificationEvent", "Updated Title");

    await EventBus.PublishAsync(eventPayload, EventHelper.GetEventName<AppointmentNotificationEvent>());

    var getRequest = RequestHelper.GetRequest($"{Url.Appointments.GetById(600)}");
    var getResponse = await Client.ExecuteAsync<AppointmentResponse>(getRequest);

    Assert.Equal(HttpStatusCode.OK, getResponse.StatusCode);
    Assert.NotNull(getResponse.Data);
    Assert.Equal(eventPayload.Title, getResponse.Data.Title);
}

โœ… Automating Edge Case Validations

Automation also ensures your system gracefully handles edge cases. What if you try to delete a non-existent appointment? Your API should reply with 404 Not Found. Let's see how we can test that:

[Fact]
public async Task Given_Invalid_Id_When_Delete_Then_Return_NotFound()
{
    var invalidId = 99999; // Non-existent ID
    var request = RequestHelper.DeleteRequest(Url.Appointments.Delete(invalidId));

    var response = await Client.ExecuteAsync(request);

    Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
}

๐Ÿ”ฅ And that's just the start! Every project has its own key flows worth automating.

๐Ÿ”‘ The Bottom Line

Automation is all about having confidence in your system. By automating HTTP status checks, event-driven workflows, and edge cases, you can spot bugs early, save time, and reduce QA overhead.
The result? Faster development cycles and more reliable software! ๐Ÿš€

๐Ÿ˜œ Curious to see it in action? Check out the demo appointments repository
GitHub Link: https://github.com/maurogioberti/microservice-appointments

#DotNetCore #QA #Automation #Testing #UnitTesting #FunctionalTesting #CleanArchitecture