2 ms·
> If you need to comment on what something is doing, usually you can move that behaviour into a function and test that function. Strong disagree. As a general
by dodobirdlord 7y ago
> If you need to comment on what something is doing, usually you can move that behaviour into a function and test that function.
Strong disagree. As a general principle, a refactoring that changes no behavior should break no tests. It's all well and good to factor out a chunk of code into a separate internal function for code clarity, but don't go writing a test for it. Don't plumb your tests through the internals of the code. If you're factoring that piece of functionality out into the public interface of another component, sure, you should test the public interface of that component. But if you're factoring it out into an implementation detail of the same component it was originally part of don't write a test that cares about the details of you implementation. The functionality it provides should already be testable via calling the function it was originally factored out of.