Discussion about this post

User's avatar
Henrik Jernevad's avatar

I really like this post, in particular the thoughts on N x M.

If a little bit of self-promotion is allowed, I wrote a blog post about a year ago that came to a similar conclusion. I think of it as a way to build robust test suites. In my ideal test suite, only a a single test would fail whenever an error occurred. I also think it could be linked to Separation of Concerns, Don’t Repeat Yourself, or the Single Responsibility Principle.

Feel free to read my thoughts: https://henko.net/blog/verify-only-what-you-need/

Expand full comment
Matteo's avatar

Hi Kent,

my worry with the composition above is that if there is a bug in doSomething(), then the state in which we execute doSomethingElse() is unknown. Continuing might be generating errors in doSomethinElse(), which are actually not a bug in doSomethinElse() but the result of executing it in a broken state.

One alternative approach could be to make it possible in the test to explicitly establish the state that doSomething() is expected to bring about. E.g.,

object := new Whatever(readyForDoSomethingElse)

result := object.doSomethingElse()

Yet another alternative would be to explicitly assert on the state that we expect object to be in after doSomething(), eg

test2()

object := new Whatever()

object.doSomething()

assumeTrue(object.isReadyToDoSomethingElse())

actual := object.nowSomethingElse()

assertEquals(expected, actual)

Some test frameworks assign a special state to tests that fail because of a failed assumption, so we might know that test2() did not fail because nowSomethingElse is broken, but because the assumptions we made do not hold

Expand full comment
12 more comments...

No posts

Ready for more?