Naming Tests
Tests should have names that describe a business feature or behavior. When naming tests, avoid:
- Using technical names for tests (as in
myMethodNameReturnsSomething
) - Leaking implementation details in test names (as in
myTestReturnsFalse
orCommandPatternTest
)
If your test names express business behaviors, when you change the technical implementation or refactor code, your test names should remain unchanged.
We have seen many developers using a test name strategy similar to ClassName_MethodName_ShouldDoSomething
. However, this can cause problems; if you rename your class or method, it confuses the meaning of your test name.