Good Practices
Good Practices
Below are some good practices to be followed in writing tests, either for legacy code or for any code for that matter
Tests should test one thing only.
Create more specific tests to drive a more generic solution (triangulate).
Give your tests meaningful names (behavior-oriented/goal-oriented names) that reflect your business domain.
Ensure you have meaningful feedback from failing tests.
Keep your tests and production code separate.
Organize your unit tests to reflect your production code (similar project structure).
Organize your test in arrange, act, and assert blocks.– Arrange (also known as Given) all necessary preconditions.– Act (also known as When) on the subject under test.– Assert (also known as Then) that the expected results have occurred.
Write the assertion first and work backward.– Write your test by first writing the assertion; don’t even worry about naming the test properly.– Write the act section of your test.– Write the arrange block if required.– Finally, name the test.
Write fast, isolated, repeatable, and self-validating tests (FIRST).
Consider using object calisthenics to drive design decisions.
Last updated