Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All

I am going to write Unit Test in my project. I am using ADO.NET application block library to perform database operation.

I want to write Test Methods for Insert, Update and Delete methods. My requirement is after inserting or updating dummy records in database, I want to clean up that data from database side, I want to rollback data in TestCleanUp method but I don't have any idea that how do I write the code in TestCleanUp method to rollback data from dababase side by using ADO.NET application block.

Any article or guidance would be helpful to me.

Next Question: Should I create dummy database for Test methods?

Thanks
Imrankhan
Posted

You didn't share any details about method. Write appropriate query(DELETE) in TestCleanUp method.

But don't disturb development database. Create a copy for testing. Check this article
Create a Sample SQL Database in Less Than 2 Minutes[^]
 
Share this answer
 
If the code you're testing talks to a database, by definition that is not a unit test (it's an integration test). Are you actually testing the database access code here? If not, you want to put the database access code behind an interface and use a mock database provider for the unit tests of application code, which logs the requests that are made to it and provides suitable data for the application code to execute. You then check that the appropriate requests were made to the database provider.

If you are directly testing database interface code, then yes, I recommend creating a throwaway database for each test. Testing the database interface code can be done with a small number of tests and small sample data so creating a database instance should be fast.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900