Unit testing is a form of software testing by which isolated source code (usually encapsulated into a single function) is tested to validate expected behavior.

When testing single units (usually functions) this leads to a robust codebase, since we are sure that each unit functions as it should. It also incentivize to develop modularized code, since each function should be a separated unit.

Libraries like PyTest for Python and Jest for Javascript/Typescript can be used to perform unit testing.

def add(x, y):
	return x + y
 
def test_add():
	result = add(1,4)
	assert result == 5, "Test failed!"

A simple example of a unit test that tests the correctness of the add function

Other types of testing are:


testing resources: