TEST_CASE with arrays as arguments (generate_test_runner) · Issue #752 · ThrowTheSwitch/Unity · GitHub
Skip to content

TEST_CASE with arrays as arguments (generate_test_runner) #752

Open

Description

@kuch3n

Is it possible to use arrays with a TEST_CASE macro? This is possible for "strings" but i can't see a way to pass other array types

TEST_CASE((uint8_t[]){0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, 0, 0, 0, 0)
void test_with_array(uint8_t const * const data, uint16_t a, uint16_t b, uint16_t c, uint16_t d)

should be equivalent to

static void runner_args1_test_with_array(void)
{
    test_with_array((uint8_t[]){0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, 0, 0, 0, 0);
}

Activity

  1. fletcher-festina commented on Sep 7, 2026

    @fletcher-festina

    I would really like this as well!

  2. SebiAi commented on Sep 17, 2026

    @SebiAi

    I have worked around this limitation by doing this:

    test_helpers.h

    #ifndef TEST_HELPERS_H
    #define TEST_HELPERS_H
    
    #include <stdint.h> // For uint8_t
    
    // For parameterized tests
    #ifndef TEST_CASE
    #define TEST_CASE(...)
    #endif
    #define UINT8_ARRAY(...) (uint_8[]){__VA_ARGS__}
    
    #endif // TEST_HELPERS_H

    my_test.c

    #include "unity.h"
    #include "test_helpers.h"
    
    TEST_CASE(UINT8_ARRAY(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0), 0, 0, 0, 0)
    void test_with_array(uint8_t const * const data, uint16_t a, uint16_t b, uint16_t c, uint16_t d) {
        // ...
    }

    This passes the parser of the generate_test_runner.rb script (no curly braces) but resolves at compile time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions