我的測試經驗主要是Ruby的Rspec。最近我嘗試編寫一個Java jUnit測試。這裏是一個例子。然後我開始懷疑這個測試是否是必要的。由於properties()
將返回Properties
或null
- 基於方法簽名。所以如果我想測試這個方法,我所要做的就是測試返回值是否爲空。這是甚至必要的測試嗎?
public class HelperTest {
@Test
public void testProperties() {
assertThat(Helper.properties(), instanceOf(Properties.class));
}
}
public class Helper {
public static Properties properties() {
// ... some code to init properties ...
return properties;
}
}
'assertNotNull(...)'有問題嗎? – Bohemian
...或'assertThat(Helper.properties())。isNotNull()'? – fge
一個永不失敗的測試,只會給人一種虛假的安全感。 –