Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.
This repository was archived by the owner on Oct 1, 2025. It is now read-only.

Should unit tests be stateless? #66

@aaaaalbert

Description

@aaaaalbert

We don't have a policy for whether unit tests must "clean up after themselves" or not, i.e. may leave traces of the state / fact of their exceution or not. Some tests clean up, some don't despite causing significant artifacts that changes the behavior of later re-runs through the same test.

Pros of requiring cleanup

  • If unit tests fail, this often means you will change code in response, and re-run the tests. Stateless tests speed this up a lot --- no re-cloning, re-building, etc.; Running the test again is like starting over anew.
  • Forces you to think harder before/while you implement. You will see problems like this in production code for sure, so why not train yourself on writing tests beforehand?

Cons of requiring cleanup

  • It's not always obvious that unit tests have side effects, and what these will be.
  • Cleaning things up correctly is complex, and probably requires lots of duplicate code across tests.

A middle ground could be to somehow mark tests that require a re-build after they have run. Then at least it's clear that problems may arise.


Reaching out to @JustinCappos, @vladimir-v-diaz, @awwad in particular --- What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions