Why we write tests and when to write tests.
Unit tests I think are essential especially when you have a complex piece of code such as computing a weighted average or turning a math formula into code.
I would be careful though when creating tests to make sure that, as you are writing the test you are always thinking how likely is this test to actually catch bugs. Too often I see tests that are testing such basic functionality that is unlikely to ever break. Make your tests useful!
One person writes the test and one person writes the code. This helps to encourage the person writing the tests to focus on what the code should do and not how it goes about doing it.
Another proposed benefit is that writing tests helps to split up your code into smaller methods. In my opinion splitting your code into smaller methods is always a good practice and depending on the person -- they may need tests to help them do this while others just do this as they code.
Finally Integration Tests tend to be too brittle and should be used carefully as not to waist too much time on them, especially maintaining them. Integration tests tend be mocked up heavily so much so that they are no longer testing real world usage. If you are going to write a integration test, once again think about what you are actually testing with it as a whole and whether or not you think the part you are testing will ever break. One should also consider whether not the test they are writing is already covered somewhere else. For instance I have seen integration tests written that in effect test a libraries functionality but this test was written outside the library thereby duplicating a test that was already including in the library.
No comments:
Post a Comment