【发布时间】:2016-06-14 11:27:47
【问题描述】:
我是 TDD 新手。我尝试实现一个从文件中读取配置并做一些事情的应用程序。
我有一个conf元素界面:
interface ConfElement{
doSomething()
}
然后我有两个 ConcreteConfElement 实现ConfElement:
ConcreteConfElementA:
class ConcreteConfElementA implements ConfElement{
private propA;
doSomething()
}
ConcreteConfElementB:
class ConcreteConfElementB implements ConfElement{
private propB;
doSomething()
}
然后我有一个工厂,它创建 ConcreteConfElementA 和 ConcreteConfElementB 从传递给工厂的 Configuration 对象中读取;
ConfElementFactory(){
public ConfElementFactory(Configuration conf)
ConfElement createConf(){
if(conf.hasElA){
return new ConcreteConfElementA();
}
else{
return new ConcreteConfElementB();
}
}
}
如何测试工厂方法?它是为 TDD 设计的吗?
【问题讨论】:
标签: java unit-testing tdd