# Is there any good way to create helper functions in a test block?

**URL:** <https://ziggit.dev/t/is-there-any-good-way-to-create-helper-functions-in-a-test-block/12019>\
**Category:** Help\
**Tags:** language, testing\
**Created:** [September 12, 2025, 3:25pm UTC](https://ziggit.dev/t/is-there-any-good-way-to-create-helper-functions-in-a-test-block/12019 "2025-09-12T15:25:30Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [September 12, 2025, 3:38pm UTC](https://ziggit.dev/t/is-there-any-good-way-to-create-helper-functions-in-a-test-block/12019/4 "2025-09-12T15:38:29Z")

</div>

@csmyx please read this:

> [@Avoid Screenshots of Text/Code](https://ziggit.dev/t/avoid-screenshots-of-text-code/5369):
>
> Why avoid Screenshots of Text/Code? I dislike screenshots of text, because they are: less accessible (text can be read via screen-readers, or braille displays) less searchable (text recognition tools often aren’t easily available / not well integrated or may contain faults in their output) annoying (you can’t easily/reliably copy the text out of a screenshot) I think these are good reasons to keep the amount of screenshots of text low in the forum and only use them, when it can’t be avoided o…

* * *

Personally I think one of the better options is to introduce a local namespace like this:

```zig
const std = @import("std");

test "example" {
    const local = struct {
        const Bla = struct {
            foo: u32,

            fn doSomething(self: Bla) u32 {
                return self.foo + 5;
            }
        };
    };

    const b: local.Bla = .{ .foo = 5 };
    try std.testing.expectEqual(10, b.doSomething());
}

```

That way you don’t have to use `@This()` and only use that builtin where it is actually required, for example when writing generics.

---

_[View the full topic](https://ziggit.dev/t/is-there-any-good-way-to-create-helper-functions-in-a-test-block/12019)._
