[Unit Testing] Best Practices of Unit Testing
1. Arrange, Act, Assert Think of each test as a hypothesis, and your test run as an experiment. Arrange; instantiate an object. Act; invoke a method and capture the reuslt. Assert; assert the hypothesis to prove it correct (or wrong). (You should 'tear down' after these 3 As) 2. One Assert per Test Method Don't have to be strictly followed, but a general guideline. Beginners have a tendency to try to test everything in one test method. But it'll be hard to pin down all the errors at once. 3. Avoid Test Interdependence Each test should handle its own setup and tear down. The test runner you use might execute several tests in parallel, and therefore, you don't want one test to depend on another test's state. While your test runner might execute your test in a particular order today, it might execute it in a different order tomorrow. To avoid confusion, just avoid test interdependence. 4. Keep it short, sweet and visible Resist the impulse t...