Martin Fowler on his website explains about self-testing code. According to his explanation, the testing not always have at first than the coding. Writing test after writing code called as self-testing code, and the coding driven by the test called Test Driven Development aka TDD. The self testing code is to guarantee that the code base is free of substantial defect, reducing more potential bugs on production. The default assumption is every non-trivial code without test is broken.
- SelfTestingCode by Martin Fowler