Object를 FileSystem으로 내보내는 JUnit-Test가 있습니다. 처음에는 내 테스트가 이렇게 보였습니다Unittest는 "assertEquals (..)"과 같은 어설 션을 가지고 있어야합니까?
public void exportTest {
//...creating a list with some objects to export...
JAXBService service = new JAXBService();
service.exportList(list, "output.xml");
}
보통 내 테스트에는 assertEquals (...)와 같은 어설 션이 포함되어 있습니다. 그래서 나는이 필요하십니까 다음
public void exportCustomerListTest() throws Exception {
// delete the old resulting file, so we can test for a new one at the end
File file = new File("output.xml");
file.delete();
//...creating a list with some objects to export...
JAXBService service = new JAXBService();
service.exportCustomers(list, "output.xml");
// Test if a file has been created and if it contains some bytes
FileReader fis = new FileReader("output.xml");
int firstByte = fis.read();
assertTrue(firstByte != -1);
}
에 코드를 변경하거나 첫 번째 방법은 충분했다? 나는 첫 번째 코드가 실제로 코드가 실행된다는 것을 "테스트"하지만 결과는 테스트하지 않기 때문에 묻는다. 또는 테스트가 통과하는 예외없이 내보내기 방법이 실행되면 "계약"에 의지 할 수 있습니까?
감사 예외없이