我是junit測試的新手,我想寫單元測試。其實這些方法不會返回任何東西。它將信號列表寫入一個csv文件。我不知道如何用void返回類型測試方法。使用JUnit測試寫入csv文件
任何人都可以幫到我嗎?
public void createCSV (final ArrayList<Signal> messages, File file)
{
try
{
// Use FileWriter constructor that specifies open for appending
csvOutput = new MyWriter(new FileWriter(file, false), ',');
// Create Header for CSV
csvOutput.writeRecord("Message Source");
csvOutput.writeRecord("Message Name");
csvOutput.writeRecord("Component");
csvOutput.writeRecord("Occurance");
csvOutput.writeRecord("Message Payload with Header");
csvOutput.writeRecord("Bandwidth(with Header %)");
csvOutput.writeRecord("Message Payload");
csvOutput.writeRecord("Bandwidth(%)");
csvOutput.endOfRecord();
for (Signal signal : messages)
{
csvOutput.writeRecord(signal.getSource());
csvOutput.writeRecord(signal.getName());
csvOutput.writeRecord(signal.getComponent());
csvOutput.writeRecord(Integer.toString(signal.getOccurance()));
csvOutput.writeRecord(Integer.toString(signal
.getSizewithHeader()));
csvOutput.writeRecord(Float.toString(signal
.getBandwidthWithHeader()));
csvOutput.writeRecord(Integer.toString(signal.getSize()));
csvOutput.writeRecord(Float.toString(signal.getBandwidth()));
csvOutput.endOfRecord();
}
}
catch (IOException e)
{
logger.error("Error in writing CSV file for messages", e);
}
finally
{
try
{
if (csvOutput != null)
{
csvOutput.flush();
csvOutput.close();
}
messages.clear();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
}
}
http:// stackoverflow可能存在重複。問題/ 3381801 /如何做我的單元測試保存文件到磁盤 – Raedwald