A complete intro to unit testing, as described in 20 minutes of IRC chatter.
Boose|work : ... the purposes of UNIT TESTING (imagine me saying that at full volume, every single time) are manifold. eqj^w^ : manfold Boose|work : MANFUL. eqj^w^ : full of men wildcard0 : beef Boose|work : Men everywhere. They use unit testing. eqj^w^ : I beefed that unit testing, bro eqj^w^ : hella beefed wildcard0 : haha Boose|work : 1. To catch 'regressions' - modules that used to work, but now don't, thanks to a change that you have inadvertently made. Boose|work : 2. To stop your idiot co-workers from changing the behavior of your modules without asking you, first. n0ob : 2.a. Unless they are smart enough to run the tests and modify them eqj^w^ : 1.b. to avoid really lame-ass errors being found in user testing and wasting someone's bench time (at my work) Boose|work : 3. To partially document the proper use of your module. ("How is this supposed to work?" "Ooooooh." ) Boose|work : 4. In the case of _interpreted_ languages, to catch errors that normally would be caught in a compilation step in _compiled_ languages. Boose|work : "Oh, shit, this function doesn't even exist. " wildcard0 : 5. to look like you're coding something day, but dont need to have anything to show for it Boose|work : ^ eqj^w^ : haha yes Boose|work : 6. The act of designing your code in order to be easily black-box testable by an outside entity also forces you to modularize the design in ways that are almost always positive. eqj^w^ : wildcard0: except last week. I have pages upon pages of labels to show for our regression test eqj^w^ : my coworker was all "this was a fun kindergarten excercise of cut and paste. I'm going to hang this in my cubicle" triskele : today's word: beef (v) beefed, beefing wildcard0 : "arts and crafts dept" wildcard0 : haha triskele : beef as a verb. Boose|work : Beefocity. eqj^w^ : wildcard0: exackly Boose|work : To write a unit test is simple. Boose|work : It's basically just a little block of code. Boose|work : You select a single THING that you want to test. Boose|work : And write code to test that THING. eqj^w^ : \o/ Boose|work : There are some guidelines that make this simpler: Boose|work : 1. If you find yourself creating and instantiating modules that _aren't_ the module you're testing, you are accidentally writing an integration test. Boose|work : 2. If you accidentally write 'creating and instantiating' as if they were two different things, you will feel FOOLISH. plypkie smirks n0ob : [[myclass alloc] init] wildcard0 : 3. You can demonstrate the difference between creating and instantiating in java very easily, though not so much in a lot of other languages Boose|work : 1a. A good way to get around this is to create 'dummy' objects that have properties similar to the ones you would be passing to your Module, but with vastly more simple behavior. In static languages, this involves a lot of magic and interfaces and mocking libraries, like "RhinoMocks" or "Moq". In dynamic languages, this is as easy as creating an object and duck-typing in whatever you need. Boose|work : 4. Frequently, unit tests are arranged as a three-part action. Boose|work : 4a. First, you 'arrange' the test, setting up all of the environment that you need to perform the test properly. Boose|work : 4b. Then, you 'act'- ideally, a single line of code that you are testing. Boose|work : 4c. Finally, you 'assert' - making assertions that check that your action has done exactly what you want it to have done. Boose|work : And finally, UNIT TESTING FRAMEWORKS. Boose|work : What has been described is a single 'unit test'. Often, when you are writing a system, you will produce dozens, hundreds, thousands of these. Boose|work : Our product is at 5400, ATM. Boose|work : .... ANYHOO, unit testing frameworks are just organizational tools allowing you to produce many unit tests and run them on demand. In most organizations that take unit testing seriously, checking in code without it first passing _every unit test_ earns you Shame and Reprisal. plypkie : Boose|work: thanks, i enjoyed your summary Boose|work : Actually, there is a good picture of our office's Shame And Reprisal Hat Tower that I shall now post. Boose|work goes link-fishing Boose|work : http://a4.sphotos.ak.fbcdn.net/hphotos-ak-ash4/s320x320/426326_101505210450... Boose|work : WE TAKE OUR HAT TOWERS SERIOUSLY IN THIS HERE TOWN