When to write unit tests

Adherents of test-driven development argue for writing the tests first. Indeed, the idea behind test-driven development is that tests define acceptance of code. In general, the Test-driven development (TDD) approach is to write a test, see it fail, and then write just enough code to make the test pass. In practice, this is easier said than done. Others argue that you should write your code and then the tests because it's more efficient. I find the most successful developers almost always develop the code and the tests simultaneously, the code influencing the tests and the tests ensuring that the code is written in a maintainable, testable way. So long as the tests are written, and written well, I find it hard to argue ...

Get Mastering Application Development with Force.com now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.