When you perform a performance boost in your system, many times you need to refactor part of the code, without changing the functionality. When you did not write the code, or it is just too complex, it might be a little bit risky and a very good test plan should be designed in order to assure that logic was not broken while boosting the performance.
When we have Unit Tests in the system it is much simpler (since someone else already done the hard work). Therefore, if your business plan is ambitious, the safe way is starting with a simple system with Unit Tests, and plan for refactoring.
I have been in a short seminar by the industry experts Dror Helper and Gil Zilberfeld from TypeMock that presented several aspects and lessons in TDD, Unit Tests and Mocks. I dropped here some of the lessons that they presented:
Moshe Kaplan
When we have Unit Tests in the system it is much simpler (since someone else already done the hard work). Therefore, if your business plan is ambitious, the safe way is starting with a simple system with Unit Tests, and plan for refactoring.
I have been in a short seminar by the industry experts Dror Helper and Gil Zilberfeld from TypeMock that presented several aspects and lessons in TDD, Unit Tests and Mocks. I dropped here some of the lessons that they presented:
- Make a single assert per function
- Name the test function FunctionName_TestDescription_ExpectedResult
- Use the appropriate Assert method in order get most information from the failure (don’t use always IsTrue)
- Keep tests simple (up to 5-6 lines each)
- Test (usually) only public methods
- Code to test, or at least in some cases use re factoring to ease problematic issues (such as pass in date to the function/class when the tested function is based on date.
- The AAA test structure:
- Arrange – set up the method/function
- Act – run the function
- Assert – call the assert method
Moshe Kaplan
2 comments:
I would like to add that Unit tests price have to be realized and calculated. The point is that unit tests is a code to be maintained with all interface changes. Sometimes it makes the change to be prohibitively expansive. This price is a factor which cause us to keep number of unit tests small.
Hi David,
You absolutely right, the cost of unit tests is not neglectable at all. However, quality cost money and we should prepare for that.
Moshe
Post a Comment