Unit Testing

Conventional unit testing (call-response) is similar to proof-by-induction. The unit test is the 1's case, where a specific number is run through an equation to prove its validity. The codes overall correctness is then determined by informal logic. The programmer must interpret whether the unit test is indicative of the code functioning correctly in other, unique scenarios.

If we were to test a routine with two distinct branches

function doThing(number) {
	if (number > 0) {
	} else {

with a single unit test


the test would verify nothing about the case where the variable number is greater than 0. The two branches have no overlapping logic, and therefor the correctness of one has no bearing on the other.

In the case of a single operation, however, a single working unit test can verify almost every outcome at once.

function double(numbers) {
  return numbers.map(num => num * 2);

The function double could be properly tested by a single unit test, as one test run relates heavily to all possible scenarios.

#software #testing