Question

I am starting new project from scratch and I would like to have high unit tests coverage. Let's say that we have ClassA, ClassB and ClassC and ClassATest, ClassBTest, ClassCTest. Is it a good practice to use in a ClassATest real object of a ClassB and a ClassC so that all classes are tested in ClassATest or should I ClassATest use mocks of ClassB and ClassC and only real instance of ClassA should be created? I don't have any troubles to instantinate ClassB and ClassC and I don't see any reasons to use mocks here.

Was it helpful?

Solution

I would tend to use the real classes if you can.

I would mock in scenarios where I can't instantiate those classes, or they require interaction with databases or other remote systems. However if you can use the real dependent classes with no penalty (construction or performance) then that seems a decent approach to reliable testing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top