Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

unity-test-framework-c

БесплатноБез исполняемых скриптовНе проверен

Use for any question or task about unit tests for pure C code on 8-bit MCUs, Cortex-M or embedded Linux, even tests for one function, including which…

testlandот testland★ 18 звёзд на GitHub

Об этом скилле

unity-test-framework-c

Overview

This skill covers ThrowTheSwitch Unity - a C unit-testing library ("a single C file and a pair of headers") at throwtheswitch.org/unity and github.com/ThrowTheSwitch/Unity, running on 8-bit MCUs through 64-bit hosts with no preprocessor magic, no auto-generated main, and no C++ requirement.

It is distinct from the Unity game-engine Test Framework (com.unity.test-framework, a runner inside the Unity 3D editor at docs.unity3d.com, covered by unity-test-framework). The two share only a name.

Composes with:

  • ceedling-build-runner - the build orchestration that calls generate_test_runner.rb and stitches Unity + CMock + the test binary.
  • ceedling-build-runner's references/cmock.md - the CMock-generated mocks Unity asserts against.
  • qemu-system-test-runner - for running the cross-built binary on a virtual Cortex-M.
  • embedded-coverage-strategy-reference - for the gcov / llvm-cov instrumentation.

When to use

  • Unit-under-test is pure C (not C++). For C++ use googletest-embedded-arm.
  • Target may be tiny - Unity works on 8-bit AVR / PIC, 16-bit MSP430, and 32-bit Cortex-M0/M3/M4/M7/M33.
  • The team already has Ceedling, or wants the canonical ThrowTheSwitch-stack pairing of Unity + CMock + CException.
  • The MCU has limited RAM - Unity's footprint is dramatically smaller than GoogleTest's.

Authoring

Minimal test

#include "unity.h"
#include "ringbuffer.h"

void setUp(void) {
    /* runs before each test */
}

void tearDown(void) {
    /* runs after each test */
}

void test_ringbuffer_initially_empty(void) {
    ringbuffer_t rb;
    ringbuffer_init(&rb);
    TEST_ASSERT_TRUE(ringbuffer_is_empty(&rb));
    TEST_ASSERT_EQUAL_size_t(0, ringbuffer_size(&rb));
}

void test_ringbuffer_push_increments_size(void) {
    ringbuffer_t rb;
    ringbuffer_init(&rb);
    TEST_ASSERT_EQUAL_INT(0, ringbuffer_push(&rb, 42));
    TEST_ASSERT_EQUAL_size_t(1, ringbuffer_size(&rb));
}

int main(void) {
    UNITY_BEGIN();
    RUN_TEST(test_ringbuffer_initially_empty);
    RUN_TEST(test_ringbuffer_push_increments_size);
    return UNITY_END();
}

A Unity test is a C function taking no arguments, named with a test or spec prefix. UNITY_BEGIN() initialises counters; RUN_TEST(name) invokes setUp -> test fn -> tearDown and captures the result; UNITY_END() prints the summary and returns a non-zero exit code on failure.

Assertions

The common assertions - TEST_ASSERT_TRUE(c), TEST_ASSERT_EQUAL_INT(a,b) (with _INT8 / _INT16 / _INT32 / _INT64 and _UINT / _HEX widths), TEST_ASSERT_EQUAL_FLOAT(a,b) / TEST_ASSERT_FLOAT_WITHIN(delta,a,b), TEST_ASSERT_EQUAL_STRING(a,b), TEST_ASSERT_EQUAL_MEMORY(a,b,len), TEST_ASSERT_NULL(p). Append _ARRAY to compare arrays (third arg is element count) and _MESSAGE to attach a custom failure string.

The full assertion-family table and the build-time config defines are in references/assertion-api.md.

Skipping and failing explicitly

void test_only_when_calibrated(void) {
    if (!device_calibrated()) {
        TEST_IGNORE_MESSAGE("device not calibrated; skip");
    }
    /* normal asserts */
}

TEST_IGNORE() records an "ignored" result, distinct from pass/fail in the summary.

generate_test_runner.rb

The Ruby script auto/generate_test_runner.rb scans a test file, finds every test_* and spec_* function, and emits a <file>_Runner.c that wires them up:

ruby /path/to/Unity/auto/generate_test_runner.rb \
    test/test_ringbuffer.c test/test_ringbuffer_Runner.c

Then compile test_ringbuffer.c + test_ringbuffer_Runner.c + unity.c and link. Ceedling does this implicitly - see ceedling-build-runner.

Building

Host build (fast inner loop)

gcc -Wall -O0 -g -DUNITY_INCLUDE_DOUBLE \
    -I src -I ext/Unity/src \
    src/ringbuffer.c \
    ext/Unity/src/unity.c \
    test/test_ringbuffer.c test/test_ringbuffer_Runner.c \
    -o test_ringbuffer
./test_ringbuffer

-DUNITY_INCLUDE_DOUBLE enables the _DOUBLE macros (off by default to save flash on tiny MCUs - per the Unity config docs).

Cortex-M0 cross-build (under QEMU)

arm-none-eabi-gcc -mcpu=cortex-m0 -mthumb -O0 -g \
    -DUNITY_OUTPUT_COLOR \
    --specs=rdimon.specs \
    -I src -I ext/Unity/src \
    src/ringbuffer.c ext/Unity/src/unity.c \
    test/test_ringbuffer.c test/test_ringbuffer_Runner.c \
    -o test_ringbuffer.elf -lrdimon
qemu-system-arm -M mps2-an385 -cpu cortex-m0 \
    -nographic -semihosting-config enable=on,target=native \
    -kernel test_ringbuffer.elf

--specs=rdimon.specs provides the ARM semihosting library ([developer.arm.com GNU Toolchain](https://de

Полный SKILL.md на GitHub

Установить unity-test-framework-c в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

.tessl-plugin/plugin.jsonreferences/assertion-api.mdreferences/ci-integration.md

FAQ

Что делает скилл unity-test-framework-c?

Use for any question or task about unit tests for pure C code on 8-bit MCUs, Cortex-M or embedded Linux, even tests for one function, including which framework fits a tiny-memory target: ThrowTheSwitch Unity (not the Unity game engine) with TEST_ASSERT families, setUp and tearDown, RUN_TEST, the test runner generator, config defines and CI via Ceedling JUnit XML.

Как установить скилл unity-test-framework-c?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл unity-test-framework-c запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить unity-test-framework-c с