Test More for Java?!

Any one know, does there exist a TestSimple/More (from Perl) for Java like the module for Perl?

whats that you say? I wrote about TestMore in Perl and PHP Here and here also!

I did a quick scan with google didn't give me much hope. So I wrote this quickly on the train this morning, since I can't hardly stand to program in any language without a TestMore like implementation.. (I know there's JUnit, and I'ved used it before, but its alot of overhead.. I just needed some quick tests!)

Class: (not making any claim this is the best or greatest way, and not 100% TAP protocol)

JAVA:
  1. package com.myawesomesite.util;
  2.  
  3. public class TestSimple {
  4.  
  5.  private int testCount;
  6.  
  7.  public TestSimple() {
  8.   this.testCount = 0;
  9.  }
  10.  
  11.  public void ok(boolean truth, String message) {
  12.   this.testCount++;
  13.   System.out.println( (truth ? "ok " : "not ok ")
  14.                       + this.testCount + " - "
  15.                       + message);
  16.  }

Usage:

JAVA:
  1. package com.myawesomesite.java;
  2.  
  3. import com.myawesomesite.java.*;
  4. import com.myawesomesite.util.TestSimple;
  5.  
  6. public class TestAnimal {
  7.  
  8.  public static void main(String[] args) {
  9.   TestSimple test = new TestSimple();
  10.  
  11.   Dog bob = new Dog();
  12.  
  13.   bob.setColor("green");
  14.   bob.setCollarSize(10);
  15.  
  16.   test.ok(bob.getColor() == "green", "bob's color is green");
  17.   test.ok(bob.getCollarSize() == 10,"bob's collar size is 10");
  18.   test.ok(bob.getCollarSize() == 0,"bob's collar size 0");
  19.  
  20.  
  21.  }
  22.  
  23. }

output is:

ok 1 - bob's color is green
ok 2 - bob's collar size is 10
not ok 3 - bob's collar size is 0

Leave a Comment