Software:Self-testing code

From HandWiki
Revision as of 12:53, 24 March 2020 by imported>WikiG (cleaning)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Self-testing code is software that incorporates built-in tests (see test-first development).

In Java, to execute a unit test from the command line, a class can have methods like the following.

// Executing <code>main</code> runs the unit test. 
public static void main(String[] args) {
    test();
}

static void test() {
    assert foo == bar;
}

To invoke a full system test, a class can incorporate a method call.

public static void main(String[] args) {
    test();
    TestSuite.test();    // invokes full system test
}

See also

Further reading

Self-testing code explained by Martin Fowler