Comments on: Wrap Your Unit Tests in Transactions https://www.chinhdo.com/20090205/wrap-tests-in-transactions/ Chinh's semi-random thoughts on software development, gadgets, and other things. Fri, 03 Apr 2020 13:28:52 +0000 hourly 1 https://wordpress.org/?v=6.9.1 By: Rob Wilson https://www.chinhdo.com/20090205/wrap-tests-in-transactions/comment-page-1/#comment-135920 Mon, 16 Apr 2012 23:49:27 +0000 https://www.chinhdo.com/20090205/wrap-tests-in-transactions/#comment-135920 Love this idea. So simple, yet very effective.

I have to slightly disagree with Gary. How would you then run an automated unit test without having to manually update your test data each time? For example, say your unit test inserts “Johh Doe” with a Client_Insert proc. Let’s say your unit test then runs a read to make sure the insert was successful, and you have to test if “John Doe” now exists. No matter what specifically you test, you would have to update the test manually before you can run it again.

Additionally, you can still test your CRUD operations AND use transactions. Why not run whatever you are testing (say, an insert), and then run a read operation to verify, inside the same transaction scope? That way, you can fully test your CRUD operations, while still having the flexibility to roll it back when the test is complete.

I personally like to separate my Database Unit Tests from Data Access Unit Tests.. meaning that I won’t test my CRUD operations in the same unit test that is testing something like a DAO.

Great article Chinh Do!

]]>
By: Gary Woodfine https://www.chinhdo.com/20090205/wrap-tests-in-transactions/comment-page-1/#comment-107915 Tue, 08 Nov 2011 14:19:42 +0000 https://www.chinhdo.com/20090205/wrap-tests-in-transactions/#comment-107915 This appraoch makes your tests a little clunky, and you are adding more logic to your tests than required. Checking that CRUDs work is a part of the Database Unit tests.

Strictly speaking your appraoch above is not for Unit Tests, but can be more closely attributed to Integration Tests.

]]>