0

I wrote a class creating connection to a remote database, query and do some more actions on that. Which is the best way/ strategy to test that kind of class? I tried to mock third party functions creating connection but I don't think it is the right way. Any help is appreciated. If you need more info, let me know.

  • what is your objective? – Yu Zhang Jun 26 '18 at 8:08
  • I don't know how to test my class/adapter? – achilles Jun 26 '18 at 8:09
  • Where is the relevant code? – Vishal Aggarwal Sep 25 '18 at 1:28
1

To test something like this you want your test to not care whether it's connecting to the actual remote database or to a mock database that you manage yourself. It can be an actual, if lightweight, database or a coded representation of one. As long as the class you want to test does not use hard-coded values to connect, you should be able to do this.

You can find more information in this blog post (which I found in a quick google search). This Stack Exchange question and its answers also offer a wealth of suggestions.

The important thing is that the method you choose works for your purposes. Depending on what you need your class to do, using it in an application with extensive logging may be sufficient.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.