3 ms·
The advantage to writing test first is that it allows/forces you to test the test. If you write the test before you've written the code, then you'll be expecti
by strommen 14y ago
The advantage to writing test first is that it allows/forces you to test the test.
If you write the test before you've written the code, then you'll be expecting the test to fail (in a very specific way) the first time it is run. By observing this you ensure that the test actually exercises the application code that you intended.
If you write the test after you've written the code, then you'll be expecting the test to pass the first time it is run. However if there is a bug in the test, it may pass for the wrong reason - e.g. if you forget some part of the test setup that causes the relevant application code to get skipped entirely.