I have a Wrapper class in C# called MyService for a ThirdPartyService API. I would like to create some tests for this MyService to make sure I'm handling all cases as expected.
ThirdPartyService has the following methods that it exposes and which we consume in different places through MyService wrapper.
MethodToCreateMethodToSubmitMethodToSchedule
The third party library often returns errors when different types of bad things happen, like
- when there is a network problem
- when there is a timeout
- when the third party service is down
- many other cases
It also returns the actual results when things are working fine.
So I'd like to create a MyServiceTestDouble class that would help me test these cases. But I'm stuck where I need to make the methods in MyServiceTestDouble return different types of output depending on my unit test. Like when it is a good case that I am testing, I would like it to return proper actual results. When my test case is for testing Exceptions, I would like the methods in MyServiceTestDouble to return appropriate exceptions.
What is the best approach to do this?
The one approach I think that will work is to create a MyServiceFactory that returns different Test Double Implementations based on the Unit test case scenario. But this would mean I need to have multiple implementations of MyServiceTestDouble like MyServiceTestDoubleGood. MyServiceTestDoubleNetworkExceptions, MyServiceTestOutageExceptions etc. I'm pretty sure that there could be a better way that I'm currently not aware of.
I would like to know if there are any unit testing framework that would help with this sort of testing.
I would also like to know if this is possible in a more elegant way without using any frameworks.
Aucun commentaire:
Enregistrer un commentaire