Test More for Java?!


JavaTesting

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 on my blog awhile back: 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)

package com.myawesomesite.util;

public class TestSimple {

 private int testCount;

 public TestSimple() {
  this.testCount = 0;
 }

 public void ok(boolean truth, String message) {
  this.testCount++;
  System.out.println( (truth ? "ok " : "not ok ")
                      + this.testCount + " - "
                      + message);
 }

Usage:

package com.myawesomesite.java;

import com.myawesomesite.java.*;
import com.myawesomesite.util.TestSimple;

public class TestAnimal {

 public static void main(String[] args) {
  TestSimple test = new TestSimple();

  Dog bob = new Dog();

  bob.setColor("green");
  bob.setCollarSize(10);

  test.ok(bob.getColor() == "green", "bob's color is green");
  test.ok(bob.getCollarSize() == 10,"bob's collar size is 10");
  test.ok(bob.getCollarSize() == 0,"bob's collar size 0");


 }

}

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