A simple C project setup for practicing Test-Driven Development using the Unity testing framework.
├── src/ # Source files
├── include/ # Header files
├── test/ # Test files
└── unity/ # Unity testing framework
make test # Compile and run tests
make clean # Remove test binary- Red - Write a failing test
- Green - Write minimal code to pass the test
- Refactor - Improve the code while keeping tests green
Edit test/test_calc.c:
void test_example(void)
{
TEST_ASSERT_EQUAL_INT(expected, actual);
}
// Register in main():
RUN_TEST(test_example);TEST_ASSERT_EQUAL_INT(expected, actual)
TEST_ASSERT_EQUAL_STRING(expected, actual)
TEST_ASSERT_TRUE(condition)
TEST_ASSERT_FALSE(condition)
TEST_ASSERT_NULL(pointer)
TEST_ASSERT_NOT_NULL(pointer)See the Unity Assertions Reference for all available assertions.