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 for or against writing the tests first. Indeed, I find it most flexible to write the tests at the same time as the code. The central question of unit testing your code isn't when to test or what to test, but how to test.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.228.88