As I mentioned in my post on Test Style: AAA or GWT, I’ve deliberately started thinking of everything in terms of GWT (Given-When-Then). So, when I’m beginning to write a new test, instead of writing this:

// Arrange
// Act
// Assert

I write this:

// Given
// When
// Then

Regardless of the style, though, if I can’t think of what should go in each one of those sections, I may have one of two problems:

  • I don’t have enough requirements, or
  • I don’t understand the requirements I have

I’ve gotten into the habit of thinking this way: No GWT, no code!

The reason for that is: if I either don’t have enough requirements or don’t understand the ones I have to a point where I can’t fill out my GWT sections, then I should NOT be writing any code. Whatever code I write is very likely to be thrown away, and unless I have a lot time in my hands to be simply toying with writing code, I should refuse to write any code and go find help to have a clear idea about what I’m supposed to implement.

9 responses to “No GWT? No code!”

  1. […] of the points I bring up on this presentation is my “No GWT, no code!” movement. 🙂As it turns out, people are responding well to that! At some conferences and user […]

  2. […] I went from Arrange-Act-Assert to Given-When-Then. From that, the next step had to be the “No GWT? No code!” […]

  3. […] Many times I don’t even know how I’ll actually implement the specs/tests, but I still write those English sentences before trying to write any code. No GWT, No Code! […]

  4. Pedro Irán Méndez Pérez Avatar
    Pedro Irán Méndez Pérez

    I agree but I always have troubles with Given part, I mean with the description, I found that When and Then is easy to describe the most of the tests, What I am missing?

    1. Hi Pedro.

      Thanks for reading and contributing the question.

      A good old friend of mine has dropped the Given in favor of When, and I do see people having trouble writing the Given and When parts.

      I still believe in keeping those separate and honing the skills of writing them. This is how I see it:

      Given = where are we starting from? What has happened in the past that has put us here?
      When = in the present, what am doing or just about to do, or what has just happened?
      Then = what’s expect in the future that follows what happens in the present?

      Framing my thoughts and the conversation with others through those lenses help us achieve greater clarity, in my experience.

      I’ll gather my thoughts on this and put out a dedicated post.

    2. Pedro, I hope this post I put out last week might help a little: https://lassala.net/2024/05/23/given-when-then-past-present-and-future/

  5. […] 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! […]

  6. […] That’s why I often say: No Given‑When‑Then, 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