Skip to main content

Posts

Showing posts from April, 2020

Clean Code from the Trenches - Writing Executable Specifications with JUnit 5, Mockito, and AssertJ

Executable Specifications are tests that can also serve as design specifications. They enable technical and business teams to get on the same page by enabling the use of a common language (in DDD-world this is also known as Ubiquitous Language ). They function as documentations for the future maintainers of the code.  In this article we will see an opinionated way of writing automated tests which could also function as Executable Specifications. Let's start with an example. Suppose we are creating an accounting system for a business. The system will allow its users to record incomes and expenses into different accounts. Before users can start recording incomes and expenses, they should be able to add new accounts into the system. Suppose that the specification for the "Add New Account" use case looks like below - Scenario 1 Given account does not exist When user adds a new account Then added account has the given name Then added account has the