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.

8
  • 3
    It is a little difficult to imagine that simply moving code to other objects reduces the number of code paths that need testing. It might become easier to see what tests need to be written, but an if-elseif-else is still 3 paths, no matter which class the logic belongs to. Commented Nov 18, 2021 at 23:32
  • I agree with Greg here, and that is the reason that I ask this question. Refactoring only splits one function into many, but the total number of codepaths is still the same if you actually refactor properly and don't end up changing the algorithm. Commented Nov 19, 2021 at 0:53
  • 1
    @FilipMilovanović: refactoring doesn't mean you completely rewrite the internals. It could simply mean you split the code into multiple functions - essentially giving a name to a group of statements without actually changing the number of code paths. Commented Nov 19, 2021 at 12:22
  • 2
    @GregBurghardt: Let's say I flip a coin, roll a die, and pick one letter, all in one go. That's 2×6×26=312 possible outcomes. But if I have a separate coin flipper, that has 2 possible outcomes. A dice roller has 6 outcomes. A letter picker has 26 outcomes. So you now only write 2 coin picking tests, 6 dice rolling tests, and 26 letter picking tests, for a total of 34 tests. That's an almost 90% reduction in how many outcomes you need to test. Commented Nov 21, 2021 at 9:54
  • 1
    @Caleth: And the need for 100% coverage of the state space dissolves due to rigorous unit testing of individual components; a handful of integration tests can confirm the integration of the components. If you demand 100% coverage, sure, then you have to cover 100%. But then you inherently choose to work hard, not smart; rendering the basis of the question moot. Commented Nov 22, 2021 at 12:50