Unit Tests as a learning tool - a good idea?

Posted by Ekkehard.Horner on Programmers See other posts from Programmers or by Ekkehard.Horner
Published on 2011-03-05T18:52:05Z Indexed on 2011/03/05 23:32 UTC
Read the original article Hit count: 365

I'm interested in ways and means for learning (a) programming language(s) efficiently. I believe that using Unit Test concepts and infrastructure early in that process is a good thing, even better than starting with "Hello world".

Why: To write a decent program even for a toy/restricted problem in a new language, you'll have to master many heterogenous concepts (control flow & variables & IO ...), you are tempted to glance over details just to get your program 'to work'. Putting (your understanding of) the facts about the new language in assertions with good descriptions (=success messages) enforces thinking thru/clearness/precision. Grouping topics and adding assertions to such groups is much easier than incorporation features from the 2. chapter of your "Learning X" book to your chapter 1 program.

Why not: 'Real' Unit Tests are meant to output "1234 tests ok; 1 failure: saveWorld() chokes on negative input"; 'didactic' Unit Tests should output relevant facts about the new language like

perl6 10-string.t
# ### p5chop
...
ok 13 - p5chop( "cbä" ) returns "ä"
ok 14 - after that, victim is changed to "cb"
# ### (p6) chop
...
ok 27 - (p6) chop( "cbä" ) returns chopped copy: "cb"
ok 18 - after that, victim is unchanged: "cbä"
# ### chomp
...

So (mis?)using Unit Tests may be counterproductive - practicing actions while learning you wouldn't use professionally.

How: Writing 'didactic' Unit Tests in languages with lightweight testing systems (Perl 5/6) is easy; (mis?)using more elaborate systems (JUnit, CppUnit) may be not worth the effort or not suitable for a person just starting with a new language.

So

  1. Is using Unit Tests as a learning tool a bad idea?
  2. Can the Unit Test tool(s) of your favourite language(s) used didactically?
  3. Should implementation details (eventually) be discussed here or over at stackoverflow.com?

© Programmers or respective owner

Related posts about programming-languages

Related posts about learning