I find it interesting that you used graphics for your examples, which is among the areas it is hard to automate tests for (there is a lot of complexity behind “verify a rectangle was drawn on the screen”, that we don’t notice because our visual cortexes take care of it for us), but you don’t address any of the problems with testing in this domain.
EDIT: Moving the article from discussion has changed its URL and the comments’ URL. Corrected link (Original left to illustrate problem). It would be better if articles and comments had URL’s that do not indicate their section, and let the section just affect index pages and feeds.
I agree that it’s not a particularly realistic example. Do you have any alternate suggestions? I’m trying to target people who are not so familiar with programing, and in doing so I valued simplicity over realism. However, assuming some of the readers go on to try some actual TDD, they might try graphics programming first and discover that it’s unpleasantly frustrating to test.
You want a program that can invert matrices. You write a test that calls the program, passing it a matrix. The test multiplies the original matrix with the result from the invert program, and verifies that the product is unity.
This is a good case to use TDD because the test is simpler than the program you are testing.
Also, an important part is to test edge/corner cases. In the matrix example, there should be a test that passes the invert program a singular matrix, and validates that it returns an appropiate error.
I find it interesting that you used graphics for your examples, which is among the areas it is hard to automate tests for (there is a lot of complexity behind “verify a rectangle was drawn on the screen”, that we don’t notice because our visual cortexes take care of it for us), but you don’t address any of the problems with testing in this domain.
This leads me to agree with jimrandomh’s affective death spiral theory.
EDIT: Moving the article from discussion has changed its URL and the comments’ URL. Corrected link (Original left to illustrate problem). It would be better if articles and comments had URL’s that do not indicate their section, and let the section just affect index pages and feeds.
I agree that it’s not a particularly realistic example. Do you have any alternate suggestions? I’m trying to target people who are not so familiar with programing, and in doing so I valued simplicity over realism. However, assuming some of the readers go on to try some actual TDD, they might try graphics programming first and discover that it’s unpleasantly frustrating to test.
Good example:
You want a program that can invert matrices. You write a test that calls the program, passing it a matrix. The test multiplies the original matrix with the result from the invert program, and verifies that the product is unity.
This is a good case to use TDD because the test is simpler than the program you are testing.
Also, an important part is to test edge/corner cases. In the matrix example, there should be a test that passes the invert program a singular matrix, and validates that it returns an appropiate error.