문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top