Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Block port for integration testing

Is there a way to block a port for running Java application, to emulate connectivity failures, for false-positive tests:

  • Block connection to DB to emulate **DB failure
  • Block connection to JMS to emulate JMS failure
  • Block connection to Internet to emulate behavior in standalone mode

I am talking here about integration testing, with standalone jetty server, which is running on the same machine but in a different JVM. So I am looking for a more generic mechanism for port blocking, than those of a Mock frameworks.

like image 498
mavarazy Avatar asked Jul 03 '26 18:07

mavarazy


1 Answers

A mocking framework, e.g. Mockito can be used to test such cases. e.g. Using mockito, you can mock a DBConnection class, so that when you try to invoke method to run SQL query, you can make that method throw ConnectionException or timeout to test how your application responds to such cases.

like image 142
MoveFast Avatar answered Jul 05 '26 11:07

MoveFast



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!