How do you write TDD-friendly tests in testo? Here's our take — no body pollution #31
ShaDowMak
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
We migrated our Go test suite from
allure-gototesto. Along the way we built atiny package,
testkit, that solves a specific problem: how to mark each test asunitorintegrationwithout repeating the label in every test body.The motivation was the TDD loop. Three kinds of noise kept getting in the way of a
fast red-green cycle:
allure-results— eating memory and addingseconds to every iteration.
t.Layer("unit"),t.Parallel()), and you had to remember to do it consistently — forgetting at.Parallel()silently broke the parallelism contract.actual logic.
testkit removes that noise entirely: call
testkit.UnitTest/testkit.IntegrationTestand the layer is set, parallelism is the default, and the body stays pure.
The problem
testo.Options(...)is global and not bound to a concreteTtype. If you set thelayer via global options (
testo.Options(allure.WithLabels(...))), then when unitand integration tests run side by side, every test gets both labels — layers
don't separate.
The solution
The trick is to make the layer a scoped option, attached inside small prefilled
helpers instead of globally:
Scoped options apply only to the test they're attached to, so unit and integration
stay cleanly separated. The layer becomes declarative — you read it from the
wrapper name, not from the body — and it can't be forgotten.
Before / After
Before (
allure-go), the test body was a mix of meta and logic — the "pollution"this post is about:
After (
testkit), the body is just the logic — no pollution:The layer and parallelism are handled by the wrapper, so the two
must rememberlines are gone — and so is the risk of forgetting them.
The full package
Other choices worth mentioning
Tcomposes*testo.T,*parallel.PluginParalleland*allure.PluginAllure, sotests get parallelism + Allure metadata out of the box.
use
testkit.WithSynconly where tests share state.(
allure.WithExcluded(os.Getenv("GITLAB_CI") != "true")). Locally the TDD loopstays fast and clean: no
allure-resultsdirectory is produced, so there isnothing to clean up between runs. The report only shows up where it's actually
used — CI.
Suiteis imported directly fromtestorather than re-exported, so testkitdoesn't break when the upstream
Suiteinterface grows.Feedback very welcome — especially on the layering approach and how it compares to
what others do with suites and tags.
All reactions