Unit Testing

Unit Testing

Write unit tests according to the basic guidelines below.

  • Test public methods.
  • Mock dependency objects that affect test results.
  • Avoid using disk-related dependencies where possible.
  • Do not use network-related dependencies.

Unit Testing Frameworks by Language

Personal Thoughts on Test Code

  • I think test code is a kind of insurance.
    • This means that when code changes and there is no test code, you become uncertain whether the code really works correctly. If tests exist, that anxiety disappears.
    • Since people write code, everyone makes mistakes. When you write test code, you think through all possible cases and can prove behavior by running them.
    • The system can operate without tests, but I think having them makes it more dependable.
  • I think writing test code is proof that the logic works correctly.
    • It proves that the code is implemented to behave correctly.
  • Test code can become a requirements specification.
    • It helps you understand under what requirements the source code behaves and how it works.

References