views:

35

answers:

3

i'm start to learn unit testing. i wonder what is the best way to isolate class under test ?

+1  A: 

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).

Skilldrick
+1  A: 

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?

DixonD
+2  A: 

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:

Gordon