zettelkasten

Test Driven Development

Last updated: 1/9/2025

TDD is where you use tests to make sure your code is operating correctly, you use and write these tests before or while you are writing the code. Making tests ensures your past code isn't messed up by the code you just written.

The most common/important test is the unit test, where you test each individual function that you write to make sure it is working properly. For CS128 you use the Catch2 framework and the code looks a little like this:

c++
TEST_CASE("DESCRIPTION", "[TEST_NAME]"){
REQUIRE(function(x) == y);
}

A metric that was surprising to me is that the Michael Novak says there should be around 1.2-1.5x as many lines written for test cases as regular code.

See Also

  1. [[computer-science]]
  2. [[c]]