How We Achieve isolation class under test?
开发者_StackOverflowi'm start to learn unit testing. i wonder what is the best way to isolate class under test ?
By stubbing and mocking any outside dependencies and setting the environment into a known and reproducable state. You have to be somewhat more specific at what you need to know.
The following are some good resource to learn about UnitTesting:
- http://www.phpunit.de/manual/3.5/en/index.html
- http://sebastian-bergmann.de/plugin/tag/phpunit
- http://googletesting.blogspot.com/
Use dependency injection to control the dependencies of the class.
Also, the earlier you start testing, the more likely it is that your code will be easily testable/isolated (Test-driven development is the logical conclusion of this practice).
You can test class in isolation if you can avoid external dependencies of this class. One common way it to use mock frameworks (not sure about PHP ones). Is it answer to what you asked?
精彩评论