0
我想使用EasyMock來測試一個方法運行特定次數,但我不斷收到一個IllegalStateException錯誤,我不明白爲什麼。我是EasyMock和JUnit的新手,對於如何使用它們不是很熟悉,所以我不確定自己做錯了什麼。IllegalStateException - 沒有最後一個模擬調用
我的代碼是:
FileOutputStream mockWriter;
Numbers mockByte;
@Test
public void testNumbers() throws IOException{
mockWriter = createMock(FileOutputStream.class);
mockByte = new Numbers(mockWriter);
mockByte.initByte();
expect(mockByte.generate()).times(10000);
replay(mockWriter);
}
而這些方法initByte和我的號碼類生成:
public void initByte() throws IOException{
File outFile = new File("NumbersOutput.txt");
FileOutputStream f = new FileOutputStream(outFile);
for(int i = 0; i < 10000; i++){
int b = generate();
f.write(b);
}
f.flush();
f.close();
}
public int generate(){
return rand.nextInt(100001);
}