Friday, April 28, 2017

JUnit Testcase Best Practices

Tips for writing great unit tests :
  1. Test only one code unit at a time
  2. Don’t make unnecessary assertions
  3. Make each test independent to all the others
  4. Mock out all external services and state
  5. Don’t unit-test configuration settings
  6. Name your unit tests clearly and consistently
  7. Write tests for methods that have the fewest dependencies first, and work your way up
  8. All methods, regardless of visibility, should have appropriate unit tests
  9. Aim for each unit test method to perform exactly one assertion
  10. Create unit tests that target exceptions
  11. Use the most appropriate assertion methods.
  12. Put assertion parameters in the proper order
  13. Ensure that test code is separated from production code
  14. Do not print anything out in unit tests
  15. Do not use static members in a test class
  16. Do not write your own catch blocks that exist only to fail a test
  17. Do not rely on indirect testing
  18. Integrate Testcases with build script
  19. Do not skip unit tests
  20. Capture results using the XML formatter

No comments:

Post a Comment