Jump to content

Self-testing code

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Ed Poor (talk | contribs) at 12:12, 11 February 2007 (links). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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

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

   public static void main(String[] args) {

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

Executing the class from the command line invokes main, which runs the test. 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