News for hackers. Stuff that matters.
Re:Ask HN: How can a successful startup adopt a strong testi... by ZainRiz on Monday May 11, 2015 @01:36AM (#9522892)
Exactly. As you try to write tests for things that break you may find that it's actually really hard to write tests. You need to initialize a database, or your code depends on X, Y, Z, and they all need to be setup.

This is an opportunity for refactoring.

Try to refactor just the code that's affected by the bug in a way that lets you inject any dependencies that it had. You can then inject Mock, Fakes, etc, and validate that the code your refactored out works as expected.

You've now added tests and refactored your code to be more maintainable. A 2 for 1 punch.

There are no comments on this comment yet.