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删除
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编写。
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 ...
This is an exellent book on wavelet in statistics.
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 ...
Handbook of Mathematical Methods in Imaging, 2nd edition
Elementary Methods in Number Theory 信息编码的教材,非常经典的一本书。适合信息与计算科学专业及计算机等专业学习。
关于金融数学的monte carlo方法比较权威的书
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 ...
Ensemble Methods in Data Mining: Improving Accuracy Through Combining Predictions Data Mining Ensemble Methods Morgan & Claypool Publishers
- **书名**:《Numerical Methods in Scientific Computing》(科学计算中的数值方法) - **卷册**:Volume I(第一卷) - **作者**: - Germund Dahlquist(杰曼德·达尔奎斯特):来自瑞典皇家理工学院。 - Åke...
Numerical Methods in Engineering with Python 3 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有...
从给定的文件内容中,我们可以提炼出关于非线性分析的知识点,特别是围绕着Kung-Ching Chang的著作《Methods in Nonlinear Analysis》(2005年)的信息。以下是详细的介绍: 首先,《Methods in Nonlinear Analysis...
Number-theoretic Methods in Statistics - Kaitai Fang, Yuan Wang 的中文版,清晰版,方开泰、王元 合著,英文版由Chapman and Hall/CRC 出版。