Gregory K. Ruiz-Ade wrote:
I don't see what all the fuss about unit testing is (from the "waaaa, i hate unit tests" side). What's so hard about defining, in a pass/fail manner, what outputs should come from given inputs to a module of code? That, really, is the core of unit testing, isn't it?

Essentially QA in code.

Careful, QA != testing.  It's testing in code.


However ... the crying comes from the fact that writing unit tests is often more work than writing the original code. Taking a quick look at my circular buffer written in C, I have *10 times* the code doing unit tests that I have actually implementing the circular buffer. Almost all of those tests represent a bug that I had to track down--generally a boundary case (insert and delete that moves back and forth on the boundary, full/empty inserts and delete, fencepost errors, etc.)

This is probably an exception--a core data structure should get tested more strongly than most units--but I have heard that 2-3 times the code in unit tests that you have in the implementation is not unusual.

My students find this out the hard way on the project where *they* have to write their own unit tests instead of relying on mine.

Normally, I write a set of compliance tests and then start the automated tester. The students invariably rely on my tests and never write their own. This is, of course, expected from a "grade conscious" set of undergrads.

(See: http://www.phdcomics.com/comics/archive.php?comicid=929)

However, for one project, I make them fly blind. The automated tester stays off until the due date. Invariably, I have to give bonus points to the 1 or 2 students who actually tested their code because the rest of the class fails miserably. Then I extend the due date by two days while my tester runs.

After this, they now understand *exactly* how much work it is to test code. They also get a lesson in code quality, but that's a different discussion ...

Personally, I wish the data structures teacher would pound this home "Sure, the data structure is only 40 lines of code, now make sure you got all the corner cases." Although, to be fair, that class is rough enough without adding unit testing into the mix.

-a


--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list

Reply via email to