문제

I'm trying to write a test class for a class that has exactly one method. It's not too difficult of a method, but it does require some (my case two, through parameter) objects from upper layers. Problem is that in order to create those objects, other objects are needed and so on and so on. So I decided to write two inner class which function as placeholder classes for the two parameters, containing only the information I need. I set for these inner classes values for the attributes I'd expect in fully working circumstances.

Now Eclipse doesn't let me compile because of the following error:

The method produceTasks(IOrder, List) in the type AssemblyTaskFactory is not applicable for the arguments (AssemblyTaskFactoryTest.IOrder, List)"

As you guessed, produceTasks is the method I'm trying to test and the arguments are my inner classes. The error thrown is pretty clear about it; it won't accept my inner classes as valid parameters, despite having the same class names (because it's in fact a different class). I expected this to work if I used the same class and method names. Is there a workaround to make this work; or what would be the alternative to avoid making a hundred objects just to test one method?

도움이 되었습니까?

해결책

MOCK dependencies and inject them during testing.

Mockito is rather nice

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