Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is unit testing appropriate for short programs

Tags:

unit-testing

I'm not a newbie since I've been programming on and off since 1983, but I only have real experience with scripting languages like Applescript, ARexx, HyperTalk and Bash.

I write scripts to automate data entry, batch process images and convert file formats. I dabble at Processing, Ruby and Python.

Most of the programs I write are under 200 lines with at most 10 functions. I wish to write larger, more capable programs in the future. I want to improve my practices to avoid creating fragile, unmaintainable messes. The programming environments that I work in (Script Editor.app and Text Wrangler.app) have no support for automated testing.

At the scale that I'm working now and writing procedural (not OO) code, is it appropriate to write unit tests, which I understand are:

short programs to test individual functions before combining them into a fully functioning larger program.

Are unit tests worthwhile compared to their cost when making programs at this scale?

like image 254
willc2 Avatar asked Oct 14 '08 03:10

willc2


2 Answers

Yes. Anything longer than zero lines can be unit tested - usually to good effect.

like image 146
Jonathan Leffler Avatar answered Sep 24 '22 21:09

Jonathan Leffler


I'd look at the likelihood for regressions, not the number of lines of code. If your programs will live a long time and are likely to be refactored or otherwise modified, then unit test may make sense. If the code is throwaway or never likely to be modified, then unit tests probably won't be worthwhile.

like image 22
C. Dragon 76 Avatar answered Sep 25 '22 21:09

C. Dragon 76