Junit测试失败返回[Microsoft] [Pilote ODBC Microsoft Access]

时间:2012-05-31 09:49:39

标签: ms-access junit odbc

我正在为我的代码编写一组测试场景,目前我的失败并非失败。

让我解释一下。我正在测试将不正确的文件路径插入类构造函数的情况。

这应该抛出一个连接错误,或者一个文件未找到类型错误,但它实际上会抛出错误

[Microsoft][Pilote ODBC Microsoft Access] '(Inconnu)' n'est pas un chemin d'accès valide.

所以这是预期的,但我的单元测试失败,因为我找不到

的代码
@test (expected=microsoft.odbc.error.class)

这是我目前的代码块,所有的想法都非常感激......

//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

1 个答案:

答案 0 :(得分:0)

这是我的解决方案......

它可能不是非常优雅,但它有助于让我(或处于相同情况的用户)处理代码可能失败的原因。

我只是设置一个日志输出消息,说明可能的原因。

某些事情......

无法连接到指定的数据库。这可能是一个不正确的文件名(或路径)或一些其他奇怪的SQL问题(如果使用嵌入式DB,是当前由另一个用户打开的文件)。确认文件的路径以及数据库中锁定文件的存在(或不存在)。

至少它让我知道发生了什么...我想我可以设置一个奇怪的错误号码来反对我自己的设计;)

大卫

相关问题