there are two kinds of methods in one class, no matter what kinds of languages you use or applications you build: element methods (this is an ambiguous name, I know) and composed methods.
1. element methods
the responsibilities of element methods are realizing part of an algorithm, like doing a searching or sorting or setting up a component. they are implementation-oriented. so they are named from the technical point of view. and generally, the access control level for them should be private or protected.
testing element methods
the unit testing strategy for element methods generally would be
result-based testing, that is, after carrying out a series of invocations and calculating, you assert the result as expected.
2. composed methods
these methods are responsible for realizing the whole algorithm by
composing these element methods, there's no concrete calculating or lib invocations, just calling to element methods. composed methods are business-oriented, and they are public.
stick to this principle no matter what class we design (repository, or model, or presenter in mvp), the class will be more maintainable.
testing composed methods
the unit testing strategy usually used for composed methods is
state-based testing, that is, before implementing composed method, it would be helpful to come up with the
steps you gonna use to implement the business logic, and use the expectation to
drive your implementation. (ref http://martinfowler.com/articles/mocksArentStubs.html)
sometimes, it is tricky to work out all these steps that would involved in the composed methods, that doesn't matter! :) in some extent, the implementation and the test just drive each other!
and sometimes, it would seem that the state-based testing for the composed method is a kind of wast, after all, you just repeat the logic in the implementation (if you do test-driven development) or in the test (if you don't do tdd), some guys in our project even call it "faked confidence". I don't agree with that, cause it happens many times in our project that the (state-based) unit tests help us drive the design and catch the bug. but I would admit that modifying the state-based testing after the requirement alteration is annoying.
分享到:
相关推荐
Neural Network Methods in Natural Language Processing 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
The Handbook of Mathematical Methods in Imaging provides a comprehensive treatment of the mathematical techniques used in imaging science. The material is grouped into two central themes, namely, ...
Bayesian Methods in Finance provides a detailed overview of the theory of Bayesian methods and explains their real-world applications to financial modeling. While the principles and concepts explained...
学习Matlab和谱方法的经典入门教材,由SIAM的前主席Trefethen编写。
Computational Methods in Financial Engineering Computational Methods in Financial Engineering
This is an exellent book on wavelet in statistics.
Spectral Method:Spectral Methods in matlab 学习谱方法的入门基础
Recursive Methods in Economic Dynamics.Stokey.Lucas
Quantum Field Theoretical Methods in Statistical Physics Quantum Field Theoretical Methods in Statistical Physics Quantum Field Theoretical Methods in Statistical Physics
NumericalmethodsinEngineeringwithmatlab-Numerical methods in Engineering with matlab.part1.rar 老外写的数值计算方法的书,个人感觉很有用! Numerical methods in Engineering with matlab ...
Copula methods in finance,financial
Computational methods in Finance, Hirsa。计算金融必备的入门书籍
Handbook of Mathematical Methods in Imaging, 2nd edition
Elementary Methods in Number Theory 信息编码的教材,非常经典的一本书。适合信息与计算科学专业及计算机等专业学习。
Advanced Methods in Computer Graphics - With Examples in OpenGL
Focusing on graph theoretic methods for the analysis and synthesis of dynamic multiagent networks, the book presents a powerful new formalism and set of tools for networked systems. The book's three ...
Models and Methods in Social Network Analysis
Numerical Methods in Multidimensional Radiative Transfer
N. G. de Bruijn教授的Asymptotic Methods in Analysis. D. E. Knuth在TAOCP中谈到一些近似计算时经常提到本书. 这本书的有两个48页(原来的有点变形, 我另外找了一个版本补上).
NumericalmethodsinEngineeringwithmatlab-Numerical methods in Engineering with matlab.part2.rar 老外写的数值计算方法的书,个人感觉很有用! Numerical methods in Engineering with matlab ...