我正在爲我的代碼編寫一組測試場景,目前我有一個失敗並非失敗。Junit測試失敗返回[Microsoft] [Pilote ODBC Microsoft Access]
讓我解釋一下。我正在測試一個不正確的文件路徑被插入類構造函數的情況。
這應該拋出無論是連接錯誤,或者找不到文件類型錯誤,但它其實引發錯誤
[Microsoft][Pilote ODBC Microsoft Access] '(Inconnu)' n'est pas un chemin d'accès valide.
因此,這是一種預期,但我的單元測試失敗,我可以」找不到的
@test (expected=microsoft.odbc.error.class)
這裏是我當前的代碼塊,所有的想法都greately讚賞的代碼...
//test for a bad file name
@Test (expected=java.sql.SQLException.class)
public void failFileConnect()
{
this.reset();//reset and initialise our temp strings
this.Report = new String();//initialise our report info string.
//this file is imaginary, although it may look similar to the principle connect verstion it is not!
MS_mdb tFile = new MS_mdb("c:\\path\\to\\non\\existant\\file\\will\\fail");
File test = new File(tFile.getSchema());
fail("cannot connect to imaginary file!");
}//end test
在類的連接初始化與此代碼提前
schema = s; //the string file name passed into the method
String db = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+schema+";";
感謝...
大衛。
ps。我已經考慮過使用一個非常普遍的錯誤來捕獲,但是會想要這個錯誤,或者其他一些JDBC/SQL tye錯誤,但是它們都不起作用,這個消息似乎不是來自任何一個。
d
到目前爲止,還沒有評論,如果有任何信息我可以添加以幫助,或者改進我將根據需要修改的問題... – DaveM