views:

187

answers:

5

I am doing a unit testing and I need to find a way to simulate a disconnection during DB transactions without actually or physically removing the network cable..The process must be automated since this is just part of a bigger scale of unit testing. I need to check if roll backs are handled accordingly

+1  A: 

You could stop the DB server process. If you let us know which DB platform, I am sure one of us will have a shell command for you that you could execute within your unit test.

Kindness,

Dan

Daniel Elliott
Forgot to mention that this is just part of the whole process of unit testing and the process must be automated
cedric
A: 

If you are using C# or .Net, you can use Typemock to fake the connection and return the disconnection effect.

Ngu Soon Hui
+4  A: 

You could mock the Connection and throw an exception when you need connection to disconnect.

Ula Krukar
You can't test a real DB connection in a unit test - because it ceases to be a unit test. +1 for mocks!
SingleShot
A: 

write a proxy which will connect you to the DB

for example in python: http://code.activestate.com/recipes/483730/

then just kill the proxy to end to connection

Am
A: 

I just need this network to be disabled. What I did was call through C# a DOS command NETSH assigning a non-existing gateway to my test pc thus disabling or cutting the network connection, execute the test case, and then setting it back to the original to enable again the connection. Thanks for the responses.. :D

cedric