Self-testing code

Self-testing code is software that incorporates built-in tests (see test-first development).{{Cite web |title=Self-testing infrastructure-as-code |url=https://opencredo.com/blogs/self-testing-infrastructure-as-code/ |access-date=2022-12-05 |website=OpenCredo |language=en-US}}{{Cite web |title=Self Testing Code |url=https://martinfowler.com/bliki/SelfTestingCode.html |access-date=2022-12-05 |website=martinfowler.com}}

Perl packages will run their self tests when they are installed using CPAN. This ensures that they run successfully in the local environment. (There is also a testing community that tests new packages and updated packages on many different platforms.)

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

// Executing main 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

}

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.

@Test

void checkplayer() {

Board board = new Board(10);

board.addplayer(1);

int check = board.getCurrentPlayer(1);

assertEquals(1, check);

}

See also

References

{{Reflist}}

{{Authority control}}

Category:Articles with example Java code

Category:Unit testing

{{Soft-eng-stub}}