Data base application development is a critical topic nowadays since nowadays more and more applications are relying on data bases. There are many developers who have years of experience in this field and each of them has got a different way or strategy for carrying out unit tests on the data base driven applications.
The management of the complex software systems or application proves to be successful only when the data base design is good and the associated data structures are strong enough.
Unit testing of the data base driven applications is important since it ensures that your application or software system works properly in the first go itself thus preventing a number of technical problems and loss that your business can face just because of it.
There are other benefits that you get from unit testing the data base driven applications. Below mentioned are the advantages of carrying out unit testing on the data base driven applications:
1. Helps in the reduction of the amount of data redundancy.
2. Corroboration and collaboration of data.
3. Security of the data base against many bugs and errors is enhanced.
4. Management of data becomes more flexible.
Everyday a large number of clients request for web sites and web based applications. Their demand is to have a sophisticated data base driven application so that they can provide high quality functionality and services to their users. Examples of such data base driven applications include:
1. Application to search through a large data base.
2. Application to subscribe to some content.
3. Application to conduct an e – commerce.
4. Application to find articles and books within a library.
The foundation of the data base driven applications is based up on the SQL standard. Many applications make use of open source languages such as java or PHP for integrating and extending data bases such as oracle, MySQL, MS SQL and so on.
Unit testing of the data base driven applications from the point of business logic is quite straightforward including implementation via discrete modules and faking any other data needed through object mocking.
Strategies for unit testing the data base
Many strategies have been tried but none of happens to be fully satisfactory:
1. Loading a test data base with data values that are known and run against ORM. It is confirmed whether right data is coming back or not. Problem here is that to keep the data base schema updated frequently which might cause it to go out of sync. Also this strategy makes use of artificial data and therefore won’t be able to expose the bugs that occur because of erroneous input.
2. Loading a copy of the production data base and running tests against it. Here the problem occurs due to the lack of idea that what might be in the production data base at a given time. If the data changes you will also require rewriting your tests.
3.Check only whether the ORM is sending correct queries or not in response to a method call by using a mock data base server.
There are certain tips that can solve the problems with the above mentioned approaches to some extent. Keep all the scripts and schemas under source control so that the current data base schema can be created by anyone. When you catch some data that causes errors add to the sample data for ensuring that it does not recur.
To keep the test data base in sync build the data base schema using a continuous integration server, load the tests and run them. However this CI server should have access to its own dedicated data base. If you give user input at the application level then the application can be tested via standard unit tests.