Self-testing code

From English Wikipedia @ Freddythechick

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

In Java, to execute a unit test from the command line, a class can have methods like the following. <syntaxhighlight lang="java"> // Executing main runs the unit test. public static void main(String[] args) {

   test();

}

static void test() {

   assert foo == bar;

} </syntaxhighlight> To invoke a full system test, a class can incorporate a method call. <syntaxhighlight lang="java"> public static void main(String[] args) {

   test();
   TestSuite.test();    // invokes full system test

} </syntaxhighlight>In addition, Java has some Jupiter API libraries for self-testing code. assert can be used in various ways such as assert equals, which checks if the given variable is equal to the value given.<syntaxhighlight lang="java"> @Test void checkplayer() {

       Board board = new Board(10);
       board.addplayer(1);
       int check = board.getCurrentPlayer(1);
       assertEquals(1, check);
   }

</syntaxhighlight>

See also

References

  1. ^ "Self-testing infrastructure-as-code". OpenCredo. Retrieved 2022-12-05.
  2. ^ "Self Testing Code". martinfowler.com. Retrieved 2022-12-05.