cedric
cedric

Reputation: 3147

Unit Testing Network Connection

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

Upvotes: 3

Views: 1452

Answers (5)

cedric
cedric

Reputation: 3147

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

Upvotes: 0

Amirshk
Amirshk

Reputation: 8258

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

Upvotes: 1

Ula Krukar
Ula Krukar

Reputation: 13019

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

Upvotes: 5

Graviton
Graviton

Reputation: 83316

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

Upvotes: 0

Daniel Elliott
Daniel Elliott

Reputation: 22887

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

Upvotes: 1

Related Questions