Lazy post: integrated test code

2008 September 11

I'm feeling too lazy to actually code this up right now (I've been working on some contract stuff in addition to my full time job), but this has been kicking around in my head since writing ExposureUtil.

On the SomethingAwful Cavern-of-Cobol forum, someone asked why languages don't make testing a first-class construct. There are lots of good reasons not to do that, but there are some really good reasons to explore that idea. Integrated unit testing would encourage responsible design, would allow easy detection of code coverage, and perhaps most importantly, would allow me opportunities for more bad puns.

To that end, I was thinking that I could implement a [Test] tag to embed metadata which could be used to test code. The tag could specify inputs and outputs in the simplest case, or could designate a testing method, or could exempt a public function from testing. In conjunction with the tags, a "test" namespace could be used for methods devoted to testing code.

Something like this.

   [Test input_1="2" input_2="4" output="6"]
   public function add(a:int, b:int):int{
     return a+b;

The test utility would take this metadata, use it to feed the method and compare the results. A more complex method might look like this.

   var q:Object = {mom:"June", dad:"Ward"};
   [Test method="testSomething"]
   public function something():void{
     q.bro = "Wally";

test function testSomething():void{ delete q.bro; something(); TestUtil.assert(q.bro == "Wally"); return true; }

Mostly, I just wanted to name the [Test] parts. They are:

  • relatively small
  • very important
  • make your code more manly
Therefore, I call them "testicles".

I still like this idea, but if you want to take it and run with it, go for it.

privacy policy
Sponsored links