c******n 发帖数: 4965 | 1 the nasty thing about jmock is that whenever I want to mock a dependent
object, I have to abstract out the object creation,
and turn a statment like
MyClass obj = new MyClass();
into
MyClass obj = createMyClass();
while production code has
MyClass createMyClass() { return new MyClass();}
and mock code has
MyClass createMyClass() { return instance_var_mock_myclass;}
I end up having a lot of createXXX() methods in each class implemented,
furthermore, clover would complain that the createXXX() them | S********a 发帖数: 1163 | 2 lots of mockup tools.
we also use mokito and easymock as well.
【在 c******n 的大作中提到】 : the nasty thing about jmock is that whenever I want to mock a dependent : object, I have to abstract out the object creation, : and turn a statment like : MyClass obj = new MyClass(); : into : MyClass obj = createMyClass(); : while production code has : MyClass createMyClass() { return new MyClass();} : and mock code has : MyClass createMyClass() { return instance_var_mock_myclass;}
| m******t 发帖数: 2416 | 3 JMock is best used to mock interfaces, i.e., where you would inject
implementations
instead of hardcoded new SomeClass(). In the latter case the two classes
are probably
too tightly coupled to be tested separately anyway.
【在 c******n 的大作中提到】 : the nasty thing about jmock is that whenever I want to mock a dependent : object, I have to abstract out the object creation, : and turn a statment like : MyClass obj = new MyClass(); : into : MyClass obj = createMyClass(); : while production code has : MyClass createMyClass() { return new MyClass();} : and mock code has : MyClass createMyClass() { return instance_var_mock_myclass;}
|
|