Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • I agree completely with fixing the design of the code but in the less ideal world of developing for a large company with tight timelines it can be hard to make the case for 'paying off' the technical debt incurred by past teams or poor decisions all at once. To your second point much of the mocking isn't just because we want the test to only fail for one reason - it's because the code being executed can't be permitted to execute without also first handling a large number of dependencies created inside that code. Sorry for moving the goal posts on that one. Commented Mar 8, 2013 at 19:46
  • If a better design is not realistic I agree with 'Who cares if you're using the other 5 methods?' Verify the method performs the required function, not how it's doing that. Commented Mar 8, 2013 at 23:01
  • @Kwebble - Understood, however the goal of the question was to determine if there was a simple way to verify behavior for a method when you also have to mock out other behaviors called within the method in order to run the test at all. I want to remove the 'how', but I don't know how :) Commented Mar 9, 2013 at 0:28
  • There's no magic silver bullet. There's no "simple way" to test poor code. Either the code-under-test needs to be refactored, or the test code, itself, will also be poor. Either the test will be poor because it will be too specific to the internal details, as you have run into, or as btilly suggested, you can run the tests against a working environment, but then the tests will be much slower and more complex. Either way, the tests will be harder to write, harder to maintain, and prone to false-negatives. Commented Mar 11, 2013 at 13:32