From: Hugh Sasse Staff Elec Eng Date: 2003-10-13T02:00:40+09:00 Subject: Re: Ruby TDD On Sun, 12 Oct 2003, Kingsley wrote: > Hi > > When doing TDD if there is code that processes data, that comes from a user - I read this as Telecommunications Device for the Deaf at first, but I think you mean Test Driven Design. :-) > e.g. logon information. > > Should my code contain tests to check that the information is in the correct > format etc, or should I do those checks in my tests? Unit tests are to check that your code is operating correctly. They mainly exist to prove that the program performs as required, under specified conditions. Tests on your input, to validate it, are not normally part of unit testing code. If the specification is a contract, it might be that the program should fail spectacularly when given bad input, because it is only contracted to work correctly for good input. Thus this testing for arbitrary input might not be considered as a unit test. Indeed, it should be part of the program itself (if the spec says it should handle such input). > > If I do checks for valid data in my code - do I then need tests > that check that the code is checking if the user information is of > correct format etc. Well, you'd need checks for the validation code, to show that it was operating correctly. I think tests in the routines that call this would be good to have, also. > > If I just put all those types of test in my tests only - It would mean that > when someone runs the program - there are no checks in place to alert a user > that they have used invalid user information. - Unless the user runs the > tests before they run the program ! But the unit tests should be fixed anyway, so they can be run automatically as needed, not requiring interaction. So those validation of input tests don't belong in the testing harness for the program. > > I'm still confused Is this clearer now? > > Thanks > > Kingsley > Hugh