parameterless test methods and setup/teardown

Feb 27, 2013 at 10:03 PM
Edited Feb 27, 2013 at 10:15 PM
A good start, but there are two big deficiencies:

1) No setup/teardown

2) Requiring a parameter to each test method and the use of that parameter to access asserts.

Supporting parameterless signature for a test method and setup/teardown is basically defacto standard for test frameworks. And I say for good reason -- it's useful and efficient.

To fix these, I think the design of the tests needs to change from implementing an interface (ITestClass) to extending a class that exposes the asserts (so you don't need the context parameter) and implements empty setup and teardown methods that can be overridden in a test sub-class.

The resulting design would be quite similar to an older version of JUnit -- before Java supported attributes.

I suspect that another aspect of JUnit would need to be leveraged: naming test methods such that the test runner can distinguish which parameterless methods are tests and which are not. JUnit used the prefix "test".

For example, the base test class could be:
class TestClass {
    setUp() { }
    tearDown() { }
A test implementation class could look like this:
class TargetTest extends TestClass {
    setUp() { = new Target(); }
    testDefaultNameIsBlank() { areIdentiical("",; }
    testDefaultSizeIsZero() { areIdentiical(0,; }
The runner would change like this:
for (var prop in testClass) {
    if (typeof testClass[prop] === 'function' && prop.startsWith("test")) {
        try {
            testClass[prop](); //no params
            testResult.passes.push(new TestDescription(testName, prop, 'OK'));
        } catch (err) {
            testClass.tearDown(); // TODO: more error handling
            testResult.errors.push(new TestDescription(testName, prop, err));
Mar 3, 2013 at 9:39 PM
I have dealt with this in a slightly different way, but you can now...

1) Use setUp and tearDown methods - they execute on each test.

2) Inherit from TestClass and use this for assertions...
class SomeTest extends tsUnit.TestClass {
    setUp() {
        // set up before each test

    tearDown() {
        // tear down after each test

    myTest() {
        this.areIdentical(1, 1);
Mar 4, 2013 at 5:46 PM

Nice that your change is backward compatible with the previous version.