Docs/Setup, seed & teardown
#

Setup, seed & teardown

Prepare state before tests and clean up after — setup, seed, and teardown flows plus the Seed and Setup nodes.

Most tests need a starting state — a logged-in account, a record to act on, a clean environment — and some need cleanup afterward. Cofactor handles this with three flow lifecycle roles and two nodes that pull prepared data into a flow.

01Flow lifecycle roles

Every flow has a type. Standard flows are your actual tests. The other three run around them:

RoleWhen it runsTypical use
SetupBefore standard testsShared preparation — configure the environment, put the app in a known state
SeedBefore standard tests that depend on itProvision test data and hand its identifiers to the tests as variables
TeardownAfter all tests in the suite finishClean up records or state created during the run

You set the role on the flow itself. When a suite runs, Cofactor runs seeds and setup first, then your standard tests, then teardown — so each test starts from a known state and the environment is left clean.

Seed flows run on a suite regardless of their promotion state, so the data your tests rely on is always provisioned first.

02Seeding data into a test

A seed flow provisions data — for example, creating an account or an order — and exposes the values your test needs. To make a value available downstream, the seed flow must declare it as an output (from an action that captures it, or from credential outputs).

In the test that needs that data, add a Seed node that references the seed flow. Its declared outputs become variables in your flow:

$var.{seed_name}.{output_key}

For example, a seed that creates a client and outputs id makes $var.create_client.id available to later steps. See Variables & macros for how to reference and reuse these values.

A Seed node can:

  • Pin a version of the seed flow so your test always runs against the same provisioning logic.
  • Choose what a seed failure does — block the test (treat missing data as a failure) or warn and continue.

03Running a prerequisite flow inline

A Setup node references another published flow to run as a prerequisite of the current flow — useful for shared data creation or environment preparation you don't want to duplicate across tests. Use a Setup node when one flow should always run another first; use the Setup flow role when the preparation applies to a whole suite.

04Managing seed data from the catalog

The seed-data catalog is where you review what a seed provisions and manage cleanup:

  • Inspect provisioned records — open a seed entry to confirm setup completed and see the entities it created.
  • Edit declared outputs — rename or expose the values downstream steps reference; keep names specific. If a seed provisions a login, declare the fields (email, password) so a Login node can map them.
  • Add or toggle teardown — a Teardown button appears even before a teardown flow exists; it generates a cleanup flow paired to that seed. Toggle teardown off to preserve data for investigation.
  • Set an API timeout — give a seed's setup/teardown API calls more or less time without affecting other steps.

Cofactor runs a seed automatically when a downstream step depends on one of its declared outputs, so you don't need extra steps just to make those values available.

05Best practices

  • Keep seed flows small and focused on producing data, not asserting behavior — your standard tests own the assertions.
  • Declare only the outputs your tests actually consume, with clear names.
  • Pair every seed that creates persistent records with a teardown that removes them, so reruns stay clean.
  • Pin a seed version when you need a test's setup to stay stable while the seed flow evolves.
  • For disposable, fully isolated state, run against a sandbox instead of seeding shared environments.