---
name: "zt_visit_test_case"
section: "3"
platform: "linux"
package: "libzt-doc"
version: "0.3.1-4"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/zt_visit_test_case"
---

# zt\_visit\_test\_case(3)

discover test cases and their structure

## NAME

**zt\_visit\_test\_case**, **ZT\_VISIT\_TEST\_CASE**, **zt\_visit\_test\_suite**, **ZT\_VISIT\_TEST\_SUITE** – discover test cases and their structure

## SYNOPSIS

**#include \<zt.h\>**

*void*\

**zt\_visit\_test\_case**(*zt\_visitor v*, *zt\_test\_case\_func func*, *const char \*name*);

**#define ZT\_VISIT\_TEST\_CASE(v, tcase) zt\_visit\_test\_case(v, tcase, #tcase)**

*void*\

**zt\_visit\_test\_case**(*zt\_visitor v*, *zt\_test\_suite\_func func*, *const char \*name*);

**#define ZT\_VISIT\_TEST\_SUITE(v, tsuite) zt\_visit\_test\_suite(v, tsuite, #tsuite)**

## DESCRIPTION

**zt\_visit\_test\_case**() and **zt\_visit\_test\_suite**(), or more usually - under their macro from **ZT\_VISIT\_TEST\_CASE**() and **ZT\_VISIT\_TEST\_SUITE**(), are used to implement discovery for test suites and test cases. Test suites are represented as functions that visit other test suites and test cases. Test cases are represented as functions that execute actual test code.

The macros are provided as convenience to avoid having to invent names.

Typically the main test suite is passed as an argument to **zt\_main**() which handles the rest of the discovery, and if necessary, execution.

## RETURN VALUES

Visit functions do not return any value.

## EXAMPLES

The following example shows how to create a test suite with two test cases. A suite can contain any number of nested suites and test cases.

```
#include <zt.h>
static void test_foo(zt_t t) {
    printf("foo invoked\n");
}
static void suite_inner(zt_visitor v) {
    ZT_VISIT_TEST_CASE(v, test_foo);
}
static void test_bar(zt_t t) {
    printf("bar invoked\n");
}
static void main_suite(zt_visitor v) {
    ZT_VISIT_TEST_SUITE(v, suite_inner);
    ZT_VISIT_TEST_CASE(v, test_bar);
}
int main(int argc, char** argv, char** envp) {
    return zt_main(argc, argv, envp, main_suite);
}
```

## SEE ALSO

[zt\_main(3)](/zt_main/3.md), [zt\_test\_suite\_func(3)](/zt_test_suite_func/3.md), [zt\_test\_case\_func(3)](/zt_test_case_func/3.md),

## HISTORY

The **zt\_visit\_test\_case**() and the **zt\_visit\_test\_suite**() functions, as well as the corresponding macros, first appeared in libzt 0.1

## AUTHORS

Zygmunt Krynicki ⟨*me@zygoon.pl*⟩
