The Clean Test Automation Monthly is a monthly blog post that shares interesting or useful test automation content which I read during the current month. This blog post is always published on the last day of the month.
Let's begin!
Test Design
Attack of the Clones – The War on Code Duplication explains why duplicate code makes our tests hard to maintain, reveals how code duplication sneaks into our test suite, and introduces a rule that helps us to decide when we should get rid of duplicate code.
Cutting Through the Noise - The Case Against Gherkin in Automation critiques Gherkin-based test automation. The author argues that Gherkin introduces unnecessary complexity and doesn't deliver the promised collaboration benefits because non-technical stakeholders rarely engage with Gherkin scenarios. Thus, developers must manage the redundant feature files and step definitions. Finally, the author identifies three reasons why code-first approach is a better choice.
Don't Mock Your Framework: Writing Tests You Won't Regret identifies three reasons why we shouldn't mock frameworks (or libraries) which we don't own and explains how we can avoid making this mistake. Finally, the author admits that there are exceptions to this rule and identifies one such exception.
Test-Driven Development: Red, Green, Refactor! is a yet another blog post which explains what's the correct way to do TDD. The author identifies the steps of the TDD cycle and describes the purpose of each step. The thing that differentiates this blog post from most TDD articles is that this blog post provides actionable advice for writing tests and selecting the test which we must write next.
Don’t trust a test you've never seen fail: Introducing Reverse Mutation Testing reminds us that we should never trust an automated test until we have seen that it can fail. This blog post explains what's the simplest way to make our tests fail and introduces a concept called reverse mutation testing which generates mutated versions of our test cases, runs the created tests, and creates a report which identifies the tests which won't fail when they should.
Why "Shift Left" Keeps Failing is an excellent blog post which explains why our efforts are doomed to fail if we all agree to do something, but we don't make sure that everyone is on the same page. That's why we must use clear definitions and share our expectations when are making decisions like this.
Backend
Conditionally Registering JUnit 5 Extensions provides a very quick introduction to JUnit 5 extension model and identifies the drawbacks of registering extensions statically with the @ExtendWith
annotation and dynamically with the @RegisterExtension
annotation. Finally, the author explains how we can solve the problems of these extension registration mechanisms by writing a conditional extension resolver mechanism.
Testing cloud applications without breaking the bank: Testcontainers and LocalStack describes how we can minimize the testing costs of our cloud applications by writing tests which are run on development environment by using LocalStack, Testcontainers, and JUnit 5.
Shift-Left Testing with Spring Boot and Testcontainers: A Comprehensive Guide starts by providing a quick introduction to shift-left testing, Testcontains, and Spring Boot. Next, this blog post introduces three testing strategies we can use when we are writing integration and end-to-end tests, and identifies the challenges which we will face when we implement these strategies. Finally, the author provides a step-by-step guide that helps us to implement shift-left testing with Spring Boot, JUnit 5, and Testcontainers.
gRPC Testing intro: Writing the first test describes how we can implement a simple gRPC service with Java, Gradle, and Spring Boot AND write tests for our gRPC service with JUnit 5.
Testing Spring Web MVC Filter with Spring Boot identifies the limitations of unit tests and explains how we can write better tests for our filters by loading a Spring application context that contains only the web components.
Writing Unit Tests With MockMvcTester: Returning a List as JSON is my own blog post that identifies what kind of tests we should write, helps us to eliminate duplicate request building code, and describes how we can write unit tests for a REST API endpoint that returns a list as JSON.
Top 5 Spring Boot Testing Myths debunks five common myths and misconceptions about testing in Spring Boot. It explains why these myths and misconceptions were born and reveals that these myths and misconceptions aren't a problem IF we use Spring Boot in the correct way.
A Practical Guide to Testing Spring Controllers With MockMvcTester provides a quick and practical introduction to MockMvcTester
. If you don't want to read long tutorials and you want to know what you can do with MockMvcTester
, you should read this blog post.
Writing Your First JUnit Jupiter (JUnit 5) Extension provides a quick introduction to JUnit 5 extensions, explains why (and when) we should write a custom extension, and describes how we can implement two custom JUnit 5 extensions: a timer which logs the execution time of every test method and an extension which takes a screenshot when a Selenium test fails.
UI / End-to-End
What Makes the Page Object Model So Special? introduces three software design principles which make the page object model useful to anyone who is writing UI tests for a web UI or end-to-end tests for a web application.
Building and improving Page Objects, one step at a time describes how we can make iterative improvements to our page objects. The author starts with a simple page object and demonstrates how we can improve the initial page object by making iterative changes to our page object. The goal of these iterative changes is to create a page object that helps us to write well-structured test code that's both easy to read and maintain.
Automating Accessibility Checks Using Playwright describes how we can write accessibility tests with Playwright by using the axe-core
and axe-html-reporter
libraries. We will learn how we can ensure that our web application doesn't have WCAG violations and generate a test report that identifies the WCAG violations found by our accessibility tests.
Operating System Independent Screenshot Testing with Playwright and Docker explains why visual tests are flaky if they are run on different operating systems and browsers, and describes how we can solve this problem by running our tests inside a Docker container. This approach improves the reliability of visual tests because they are always run by using the same operating system and browser.
Catch Missing await
Calls in Playwright Tests with ESLint helps us to fix flaky Playwright tests before they are run. This blog post provides step-by-step instructions which describe how we can detect unhandled promises by leveraging the @typescript-eslint/no-floating-promises
ESLint rule.