Tutorial :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


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


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.




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


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


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

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »