你能幫助我嗎? 我有50場(一個字符串,整數b ...)的對象,我有這樣的「如果」語句的方法:單元測試 - 一種方法而不是50
if(a==null OR b==null OR ...(for any field)) {
throw My Exception();
}
我寫單元測試這種方法。我創建了對象的實例50這樣
1. a=null, <-- only a is null for this instantiation 2. b=null <--- only b is null for this instantiation . . . 50. n=null <--- only n is null for this instantiation
我的問題是,我必須寫這50種@Test方法?
我寫了一個這樣的@Test方法,但我不確定這是否正確根據單元測試的範例。
@Test
public void test(){
for(int a=0;a<50;a++){
try{
//I call the method with my if statament for any of 50 object
}
catch(MyException e){
y++;
}
}
Assert.assert(y,50);
}
「我有100個領域的對象」 - 難道這是你真正的問題嗎? –
如果你有一個包含100個字段的對象,那麼你沒有寫出面向對象的軟件。 –
燒掉所有東西然後重新開始? –