DEV Community

Discussion on: One assert per test - What is that about?

Collapse
 
donut87 profile image
Christian Baer

Thanks for your comment. Sometimes this might be the right choice. As I tried to express I am not an extremist when it comes to this topic. This 'bundle of outputs' might just come in the way of having clear tests with having clear names. So look out for your bundle size ;)

Collapse
 
alainvanhout profile image
Alain Van Hout

Yes indeed :).

For context, I'm mostly talking about (fairly extensive) API tests, which generally involve setting up some things (via API calls), making a single specific API call with parameters that reflect the test's concern, and then verifying that the call has had the effect it needed to.

The latter can relate to for example

  • when updating a resource, you'd expect the value(s) that were updated to have in fact been updated and the remainder to have stayed unaltered, with potentially some minor side-effects like the resource's timestamp having changed or its version to have incremented
  • when moving a resource from one collection to another, you'd expect it to no longer be present in the first collection, to be present in the second collection, and possibly that the resource itself has a reference to the second collection rather than the first

Both of those involve multiple asserts, but really only a single concern.