【发布时间】:2014-01-17 08:40:15
【问题描述】:
我是 TDD 新手,但遇到了问题。据我所知,TDD 中的所有测试都应该在生产代码准备好之前失败。我开发了以下代码:
汽车界面:
public interface CarOperations{
/**
* Return current car speed in km/h
*/
public int currentSpeed();
}
汽车类:
public class Car implements CarOperations{
@Override
public int currentSpeed() {
// TODO Auto-generated method stub
return 0;
}}
JUnit 测试:
@Test
public void testInitSpeed() {
Car car = new Car();
assertEquals(0, car.currentSpeed());
}
所以我希望这个测试会失败,因为在我开发任何生产代码之前每个 TDD 测试都应该失败,但是由于 int 默认值,这个测试会通过。我可以将方法的返回类型更改为 Integer 并接收 NULL 值,但我想知道在这种情况下如何处理原语?也许我的测试错了?
【问题讨论】:
-
相关:programmers.stackexchange.com/questions/224365/… - 在我看来,这样一个微不足道的案例不是问题
标签: java unit-testing junit tdd