From: "Mauricio Fernández" Date: 2003-02-22T07:07:11+09:00 Subject: Re: unit testing: method actions vs. results On Sat, Feb 22, 2003 at 04:43:31AM +0900, James Davis wrote: > Can unit testing be used to test (or test-first develop) methods that > *do* something rather than *return* something? E.g., play a sound, > display an image, or drop down a menu. How? TIA, You might want to use mock objects to check that your code is passing the right messages; e.g., suppose you have something like this class SoundPlayer def initialize # init device end def play(aSound) end end at some other point you're doing sp = Soundplayer.new .... sp.play ( whatever ) If you replace sp by a mock object with the same interface you can check that your code is calling the #play method. This sounds exceedingly trivial here, but you might also want to check that some methods are called sequentially... However, at some point (the lowest level) it could be difficult/impossible to unit-test automatically; hopefully you won't modify that layer once it is working so unit-testing wouldn't make that much sense anyway. As for the *real* sound: in Linux you'd for instance use /dev/dsp and at some point write the waveform data to that device file; you can instead use an object that keeps track of what was written and compares it with the expected sound. When you want to check whether some events happen in a GUI, things become complicated as you have to play with the event loop. You can however try to locate a place to substitute mock objects for the real ones. My 2 (Euro) cents. -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com (It is an old Debian tradition to leave at least twice a year ...) -- Sven Rudolph