Don’t Test Methods, Test Behaviors

Testing a method with multiple behaviors with just one test could be dangerous. Since most methods output multiple different behaviors, such as a method that sends an email that displays a notification of what they bought along with a warning of a low balance. If we were to test this method in one test we are not covering both behaviors thoroughly. So we should have two separate test, one that tests the notification and one that tests the low balance.

Testing behaviors ensures all other methods will not be affected by a bug in a behavior. Also whenever a behavior is added to a method, a new test can easily be added without disrupting previous tests.

https://testing.googleblog.com/2014/04/testing-on-toilet-test-behaviors-not.html

Leave a comment