数据库查询的单元测试

时间:2013-06-27 19:28:37

标签: java eclipse testing

如何为下面的课程编写测试用例。它检查数据库中给定查询的值。

public class DboQueryCheck {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("Start DboDaoService");
        DboDaoService dboDaoServcice = new DboDaoService();
        dboDaoServcice.build();
        String query = " select o.org_name,  l.organization_id from " +
                       " code_value cv,code_value cv_loc,code_value_outbound cvo,location l,organization o" +
                       " where " + 
                       " (cv.cdf_meaning = 'INGENI' or cv.cdf_meaning = 'MEDNEC')" +
                       " and cvo.contributor_source_cd = cv.code_value" +
                       " and cvo.alias_type_meaning = 'FACILITY'" +
                       " and l.location_cd = cvo.code_value" +
                       " and cv_loc.code_value = l.location_cd" + 
                       " and cv_loc.code_set = 220" +
                       " and o.organization_id = l.organization_id" + 
                       " order by o.org_name, cv_loc.display, cv.cdf_meaning";


        System.out.println();
        dboDaoServcice.report(query);

    }
}

1 个答案:

答案 0 :(得分:2)

你没有。在您的示例中,您测试的不仅仅是一个单元。因此,根据定义,您不能“单元”测试它。如果要对此进行测试,请至少考虑使用DBUnit或内存数据库,如H2 / HSQLDB数据库。

或者,你可以测试生成的SQL命令,但我想知道它的价值是什么。