I’m finding in this situation: I’ve a legacy service (written in C#) that just runs three threads that do some different stuff, suppose three different tasks. Now each of this task needs to be unit tested because on production stage we have a lot of bugs, unhandled exceptions and so on that makes our developers’ life very difficult.
What’s strange in my opinion is that obviously these task just expose one public method (suppose Run) and, if this is correct, I think I should unit test this one. Am I correct? How would you approach this kind of job? Which kind of refactoring would you perform?
The problem with testing a legacy class with only one public method that runs a lot of code internal is that it will never come down to the level of a Unit Test.
The nicest solution would be to refactor your code to such a level you can inject all dependencies so you can test all code paths.
If that’s not possible you to control the environment the tests run in. By differing the setup for your tests in such a way that each of the three tasks is separately run, you could check each result independently and force all error paths.