3 ms·
I'm impressed. I really thought I'd seen all approaches to unit testing, but apparently I hadn't. This really appeals to me! Is there anyone here who's been us
by skrebbel 14y ago
I'm impressed. I really thought I'd seen all approaches to unit testing, but apparently I hadn't. This really appeals to me!
Is there anyone here who's been using DocTest and has some experiences to share?
I love how, as a side effect, this approach to unit testing encourages implementing a good toString / __str__ on each class. In those languages that have that, of course.
- bryanlarsen 14y agojashkenas touches on it, but here's my rule of thumb for doctests: Test your documentation, but tests aren't documentation. In other words, it's great practice to ensure that code snippets inside your documentation execute correctly. Your primary benefit is that your documentation is correct, complete and up to date. Any testing benefit is purely secondary; you need a complete test suite regardless. You can use a doctest framework to create this test suite for convenience, but recognize that your doctests are going to be either illustrative or complete, but cannot be both. Examples: Here's a tutorial written in git comments so that each step is fully executable: http://cookbook.hobocentral.net/tutorials/agility http://cookbook.hobocentral.net/tutorials/agility Here's a manual page written in rubydoctest: http://cookbook.hobocentral.net/manual/scopes http://cookbook.hobocentral.net/manual/scopes