unser construction
Important
- Unit Test is a qualification of a system, but also it becomes an alternative of design document and usage document of the system
- So, the Unit Test must be updated with the corresponding source code
- Otherwise, the unit test-cases will become useless
Basic Concept
- An Unit Test should be corresponding to one method, a test method name should be test_[method name] or test_[method name]__case123 if needed
- Integration Test or System Test should be designed separately from the Unit Test
- If they are mixed in one test-case file, for example, it will be tough to maintain the test-cases
- We should consider Blackbox Test first, which means that we should check method interface (arguments and return values), do not care about the internal process and local (private) values
- But if we use flexmock it means the test-case will also check implicitly the internal processes and values of method like 'Whitebox Test'
- Although 'Whitebox Test' is sometimes useful to check the method process precisely, it will take much longer time to develop test-cases
- A Unit Test should be independent from the other libraries and modules by using flexmock
- otherwise, one part updating may influence on many related test-cases
- The relation or dependency among libraries should be tested by Integration Test or System Test
- Sometimes there should be several test-cases made for one method because of several processes in the method
- If you have to prepare many test-cases for one method to make the coverage 100%, it may indicate the method is too complicated or too big.
- You should consider if the method can be divided into several sub small methods, or if it is possible to use polymorphism instead of 'if' bifurcation
- Basically, many 'if' conditions should NOT be implemented in one method in Object Oriented Probgramming
- You should NOT define the tested class again in the test-case file
- It may influence on the other test-cases when you execute the test-case with suite.rb
References