Is Given-When-Then (GWT) superior to Arrange-Act-Assert (AAA)?
Interesting question: superior in what sense?
Is Angular superior to React? I have seen both great and terrible software built with both.
Is C# superior to Java? Same as above.
Is Red Bull superior to Monster? No, the Green Monster tastes better. But that’s just my preference.
To think of one thing being superior to another, I think of what needs to be achieved.
If I’m dehydrated, water is superior to wine in hydrating me.
If I’m enjoying a meal at an Italian restaurant, wine is superior to water in complementing the taste of my delicious pasta.
If I am asked to implement a user story, GWT is superior at helping me clarify the problem that needs solving.
If I collaborate with others (technical or non-technical), GWT is superior in getting everybody on the same page faster.
Notice I specifically wrote those statements from my perspective.
After many years of following that approach and receiving feedback from those I have collaborated with, I’ve validated that GWT is superior for me in achieving those outcomes and has helped my teams.
Could I achieve those outcomes through different approaches (such as AAA)? Yes, I’ve done it before knowing GWT, but I know I wasn’t as effective, and my collaborators didn’t benefit from the same level of clarity.
AAA only exists in the context of automated tests. This is a typical example:
[TestClass]
public class CalculatorTests
{
[TestMethod]
public void Add_TwoPositiveNumbers_ReturnsCorrectSum()
{
// Arrange
var calculator = new Calculator();
int number1 = 5;
int number2 = 10;
int expectedSum = 15;
// Act
int actualSum = calculator.Add(number1, number2);
// Assert
Assert.AreEqual(expectedSum, actualSum, "The Add method did not return the expected sum for two positive numbers.”);
}
}
It doesn’t matter whether this test was written before or after the feature implementation; it exists far from any meaningful conversation involving two people about the problem that needs solving. We wouldn’t see those arrange-act-assert blocks in a user story for conversation.
GWT exists in the context of conversations about scenarios of a user story. If a story describes the value of a feature that calculates results, we could see a scenario described like such:
Scenario: Addition of positive numbers
Given two positive numbers
When those numbers are added
Then the correct sum is calculated
That is a conversation starter. Depending on where the conversation goes, the scenario could be rewritten to include examples:
Given the numbers 5 and 10
When those numbers are added
Then the calculated sum is 15
Is that going to be turned into automated tests? Maybe. Maybe not.
By writing out very simple GWTs on a whiteboard during conversations, I have experienced the following:
- User stories change from high to low complexity and vice versa;
- UX/UI design discussions moving forward faster
- There have been fewer trips back to the drawing board due to presenting features to stakeholders and receiving feedback such as “nope, that’d never work because of…”
GWTs shorten the distance between the real world and code.
What about developer tests for technical things?
Yes, code is written for humans. Even when describing technical things, use plain English.
Seeing it from that perspective (people communicating and collaborating), I believe GWT is superior to AAA.
GWT helps streamline communication and collaboration with anybody, technical or non-technical. If everybody is technical, it also streamlines the conversation regardless of their levels of expertise.





Leave a Reply