How to unit test an SQL query?

前端 未结 4 1020
耶瑟儿~
耶瑟儿~ 2021-02-08 11:47

I have a class DBHandler which takes a query, runs it through the SQL server, checks for errors and returns the result. How can I unit test this class?

4条回答
  •  自闭症患者
    2021-02-08 12:36

    A quick solution for a mock db works like this:

    • Setup an HSQLDB test server independent from your app.

    • Populate with test data.

    • Use conditional code where you connect to your real database, to connect to the test server. A property in your application can control this.

    • Test the application

提交回复
热议问题