Discussion about this post

User's avatar
Jay Bazuzi's avatar

A superficially-related pattern I sometimes use, when testing that "operation `O` changes `x` from `a` to `b`:

```

setup()

assert x == a

O()

assert x == b

```

The first assertion isn't actually about testing anything, it's a message to a human reader.

Many people have told me they don't like this because they only want one assertion per test, but I think it's a good exception to that idea.

Paul-Sebastian Manole's avatar

My opinion is that people write tests like this because of the setup phase. If the testing is not done right, if the abstractions are in the wrong place, or they are wrong, or your module seams are not where they should be, it can be really costly to set up the world for a test, so that is why people bunch up multiple assertions in the same test. You see this a lot in E2E tests as well. I think altogether these experiences from writing incorrect test suites lead to this learned behaviour.

4 more comments...

Ready for more?