I was reading a thread the other day where two developers were debating test structure. One said, “Every AAA test I’ve seen is just thrown together in a single method.”
The other replied, “Is your problem AAA vs GWT, or just poorly written code? I’ll take well-written AAA over poorly written GWT every time.”
Both are right. And both are missing something.
The Pattern Isn’t the Problem
Yes, any pattern can produce good or bad results. AAA (Arrange-Act-Assert) and GWT (Given-When-Then) are both valid approaches. You can write clean tests with either. You can write messy tests with either.
But here’s what I’ve noticed: the pattern you choose influences how you think about the test, and that shapes what “clean” even means.
AAA Lives Close to Code
AAA is a code-focused pattern. When I write an AAA test, I’m thinking about:
-
Setting up objects
-
Calling methods
-
Checking return values
The cleanup work is mostly technical. I need better variable names. I need to extract helper methods. I need to understand the programming language better. The improvements show up in the code itself.
And that’s fine. If you’re proficient with the language, you can write beautiful AAA tests.
GWT Lives Close to Specs
GWT is a specification-focused pattern. When I write a GWT test, I’m thinking about:
-
The initial state of the system
-
The action someone takes
-
The outcome they expect
The cleanup work is mostly linguistic. I need clearer phrasing. I need to describe behavior, not implementation. I need to understand the domain better. The improvements show up on a whiteboard or the back of a napkin before they ever touch code.
Why Carry GWT Into the Developer’s Area?
This is the question that matters.
If both patterns can produce clean tests, why bother with GWT when you’re already writing code? Why not just use AAA and keep it simple?
Because developers get lost in technical concerns too easily.
I’ve seen it happen over and over. A developer starts writing a test. They get tangled up in mocking frameworks, dependency injection, test data builders. Before long, the test is about how the code works, not what the code does.
GWT keeps me honest. It forces me to describe behavior in plain language first. It makes me think like someone using the system, not someone implementing it.
When I write “Given I am a customer with an expired subscription,” I’m not thinking about database schemas or object constructors. I’m thinking about the scenario. When I write “When I attempt to access premium content,” I’m describing an action, not a method call.
The Glasses and the Magnifying Glass
Here’s how I picture it:
I put on my English glasses first. I describe the scenario in GWT. I make sure it makes sense to someone who doesn’t know the code.
Then I switch to my magnifying glass. I zoom into the implementation details. I write the code that makes the scenario work.
The glasses keep me focused on the right level. The magnifying glass lets me inspect the details when I need to.
If I skip the glasses and go straight to the magnifying glass, I end up writing tests that are technically correct but behaviorally unclear. I end up with comments explaining what the test is supposed to do, because the code doesn’t tell that story on its own.
What Makes Code “Poorly Written”?
The second developer in that thread asked a good question: what constitutes poorly written code?
Poorly named variables, methods, and functions, for sure. Some languages give you features to keep things tidy. But I think there’s something deeper.
Poorly written test code is code that makes you work too hard to understand why the test exists. It’s code that describes the mechanics but hides the meaning.
GWT helps with that. Not because it’s magic, but because it makes you write the meaning down first.
A Small Shift
I’m not saying AAA is wrong. I’m saying GWT gives me a better starting point.
It keeps me thinking about behavior before implementation. It keeps the test readable to people who aren’t deep in the code. And when I do need to dive into the technical details, the structure is already there to guide me.
That’s worth the extra step.





Leave a Reply