小编Nel*_*elz的帖子

部分嘲笑作为代码气味?

为什么关于"部分嘲笑"以及需要它的代码会有如此多的仇恨?

这是一个(理论上)示例实现:

public ComplexResult1 operationA(Stimulus a) {
    {
        ...
        result = ...;
    }
    auditTheChange(a);
}
public ComplexResult2 operationB(Stimulus b) {
    {
        ...
        result = ...;
    }
    auditTheChange(b);
    return result;
}
void auditTheChange(Stimulus stim) {
    // do a bunch of stuff to record the change
    // and interact with another outside service
}
Run Code Online (Sandbox Code Playgroud)

现在,根据我的理解,这是重构良好的代码.

如果我想UNIT测试operationA和operationB,确保在每个场景中都进行审计,但不必测试审计代码的细节,我会使用部分模拟.

我没有看到/理解导致如此多的项目(EasyMock,Mockito等)推荐重构?

java refactoring mocking partial-mocks

8
推荐指数
1
解决办法
1655
查看次数

标签 统计

java ×1

mocking ×1

partial-mocks ×1

refactoring ×1