Many years ago, after really getting into writing tests, I fell into the same trap newcomers do: my test code was very messy! Eventually, I heard of the AAA-style of organizing test code. AAA stands for Arrange-Act-Assert. There are several posts out there that show it. Here’s a link to one, in case you don’t know what this is all about.

After years of following that format, I learned about BDD (Behavior-Driven Development), and that’s where I learned about GWT (Given-When-Then).

Several years ago, I stopped thinking about AAA when writing any kind of test and got convinced that I should always think in terms of GWT. Why? Because AAA is too technical, while GWT works well both for technical people as well as for business or QA folks. Now, why’s that important?

For me, when I want to get feedback by having my code reviewed, if I stick with the GWT mindset, I can get pretty much anybody involved with the project to help me review my code. That means I can easily work with another developer, business analyst, or QA guy.

So, when I’m about to write tests, instead of thinking how I’m going to…

  • Arrange my test, I think what I’m Given
  • Act in my test, I think When something happens…
  • Assert the results, I think if that something happens Then this is what I expect as the outcome.

In both styles, the structure of the test is pretty much the same. However, this shift in how I approach coding makes me think more from a business-oriented point of view, and this mindset opens up possibilities regarding the number of people I can collaborate with in order to build a better product.

11 responses to “Test style: AAA or GWT?”

  1. […] « Test style: AAA or GWT? […]

  2. […] in it I say it was 2003 when I first heard of unit tests. Maybe my motivation shifted when I went from Arrange-Act-Assert to Given-When-Then. From that, the next step had to be the “No GWT? No code!” […]

  3. […] acceptance criteria, review mockups, etc, and another session to write my specs for it (only the Given-When-Then statements). My soundtrack consists of classical […]

  4. […] look at the AAA pattern from the following perspective. As Claudio Lassala states in one of his blog posts, instead of thinking of how I’m going […]

  5. […] That was my transition from Arrange-Act-Assert (AAA) to Given-When-Then (GWT). […]

  6. […] How to write better specifications in Given-When-Then […]

  7. […] posts, only 3 posts were published in 2022; all other posts have been published many years ago: the 1st and 2nd place in 2017, and the 3rd place in […]

  8. […] The most viewed post was one from the previous year, Improving my Reading System and Leveraging Obsidian, closely followed by a post from 2017, Test Style AAA or GWT? […]

  9. […] Switching from Arrange-Act-Assert (AAA) to Given-When-Then (GWT) has been a game-changer for me. I’m so convinced of its benefits that I say No GWT, No Code! […]

Leave a Reply

Trending

Discover more from Claudio Lassala's Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading