-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit testability of Package #40
Comments
Hi, I'll ask my colleague why we decided to seal these classes in the first place (my first reaction would be that anything we return should be an interface). Until then, I see the following possibilities for you:
I will get back to you on enabling mocking for internal library classes though. |
1 more thing I just found - |
I see that there are multiple models that use the sealed option, but also classes.
Scratch above idea, sealed interfaces are also hard to mock.. Let me know if you guys would be open to making the models that you are exposing either public or an interface. Interfaces would be even easier to use and test :). I can also try to make a pull request. |
Yes, if you want to unit test this way you have 3 options:
E: And yes, I agree we should not return |
I have made an interface around my own service, however, each implementation of a specific translation solution provides such different approaches that a interface is... hard to realize? For example.. both Google and Azure don't give the possibilty to even look at usage amounts. For now, i have simply removed the call to get the usage. But i would love it (also for the other models that are sealed) if they could become interfaces for testability! Looking forward to what you have discussed. |
Hi! Any further news on how deepl is planning to address the testability of these classes that are returned by the client? |
Hi, sorry for the delay. We are working on a change to allow you to mock a return value properly. |
Hi Jan! Great to hear, i look forward to the changes. For now i've wrapped Deepl's models that i am using to ensure testability of my own software. No more urgent need, but would be nice to have :) Thanks for the support! |
Another issue with testability are the exceptions: https://github.com/DeepLcom/deepl-dotnet/blob/main/DeepL/DeepLException.cs All constructors are |
^ Currently i am creating wrappers to simply wrap around the deepl exceptions for testing purposes.. alot of dumb boilerplate code for no reason, as the DeeplExceptions are essentially just wrappers themselves? |
I used reflection. Pick your poison I guess....
|
Exception have now public constructors. Thank you for this! |
Yes, thanks for the reminder :) We wanted to include arabic in the release, so this was a bit delayed. |
Describe the bug
I have implemented the deepl translator in my own package for own development. Now i am trying to unit test my own software, which means i want to essentially mock everything the translator performs. However, i can't simply Mock for example the Usage object, because it is a sealed class and it does not have an interface. I'm not sure if there is any other classes like this, but it would be nice to be able to mock these objects for tests.
Ofcourse, i can write my own layer above the translator object and Usage object, so that i can mock it.. but in my opinion this is a responsibility of the delivering library.
So.. sorry, not a bug, more like a feature request that would help every developer trying to integrate this package into their own software :)
If i've missed any approach on how to deal with the sealed classes without interface please let me know! I might have overlooked a easy way to fix the issue..
Screenshots or sample code
Heres an example of the code i would like to have in my tests:
The text was updated successfully, but these errors were encountered: