Skip to content

How to test Netherframe apps

A reliable Netherframe test suite layers fast offline checks underneath targeted provider-backed and emulator tests so you catch authoring mistakes in milliseconds and verify real cloud/state behavior where it counts.

For a guided first test, start with Tutorial: Test an app without cloud credentials.


Choose the right testing layer

Layer What it proves Requirements Speed
1. Construct & synthesis tests Resource counts, stable IDs, attributes, provider wiring, cross-stack references, Teardown[T] invariants Python + pytest only Milliseconds
2. Offline policy linting (app.lint()) Schema conformance and organization/AWS security rules (netherframe.lint.hashicorp.aws) Installed lint packs Milliseconds
3. In-memory / FakeCloud tests (nf.testing) Plan/apply/destroy lifecycle, rollback, retention, checks, finalizers, AWS API behavior locally netherframe.testing, provider binaries, Docker (for FakeCloud) Seconds
4. Live sandbox plan/apply Real cloud IAM, provider quirks, remote backend permissions Cloud credentials + disposable account Seconds–minutes

1. Write fast construct and synthesis unit tests

Build a fresh App per test and synthesize into pytest's tmp_path so tests stay isolated and never touch real state:

import json
import tempfile
from pathlib import Path

from nf.core import App, Output, Stack
from nf.providers.hashicorp.aws import AwsProvider, S3Bucket


def build_storage(bucket_name: str) -> App:
    app = App(nf_id="platform")
    stack = Stack(nf_scope=app, nf_id="storage")
    AwsProvider(nf_scope=stack, nf_id="aws", region="us-east-1")
    bucket = S3Bucket(nf_scope=stack, nf_id="assets", bucket=bucket_name, tags={"Env": "prod"})
    Output(nf_scope=stack, nf_id="bucket_id", value=bucket.output.id)
    return app


with tempfile.TemporaryDirectory() as tmp:
    app = build_storage("acme-prod-assets")
    app.synth(outdir=tmp)
    doc = json.loads((Path(tmp) / "platform" / "storage" / "nf.tf.json").read_text())
    assert doc["resource"]["aws_s3_bucket"]["assets"]["tags"] == {"Env": "prod"}
    assert doc["output"]["bucket_id"]["value"] == "${aws_s3_bucket.assets.id}"

What to assert:

  • Stable nf_id addresses for stateful resources (buckets, databases, KMS keys)
  • Required tags, encryption settings, and LifecycleRules(retain=...) / prevent_destroy
  • Cross-stack references and output expressions
  • Environment branching across dev / staging / prod inputs

Avoid asserting every provider default attribute—focus on your app's own contract.


2. Assert offline policy rules in tests

Combine pytest with app.lint() to enforce security and schema policies before CI ever touches cloud credentials:

from nf.core import App, Provider, Resource, Stack
from nf.lint.hashicorp.aws import rule_pack

with App() as app, Stack(nf_id="monitoring"):
    Provider(nf_id="aws", nf_type="aws", region="us-east-1")
    Resource(
        nf_id="logs",
        nf_type="aws_cloudwatch_log_group",
        name="/app/logs",
        retention_in_days=365,
        kms_key_id="arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012",
    )

report = app.lint(packs=(rule_pack(),))
report.assert_valid()

See Offline policy linting for custom rule packs and CLI usage (nf lint).


3. Test teardown inputs and app factories

If your app declares Teardown[T] inputs, verify in unit tests that toggling them changes only lifecycle policy and never alters the deployed resource shape:

from nf.core import App, LifecycleRules, Stack, Teardown
from nf.core.execution.teardown_inputs import deployment_shape, shape_differences
from nf.providers.hashicorp.random import Pet, RandomProvider


def shop(keep_orders: Teardown[bool] = False) -> App:
    app = App(nf_id="shop")
    stack = Stack(nf_scope=app, nf_id="data")
    provider = RandomProvider(nf_scope=stack, nf_id="random")
    Pet(
        nf_scope=stack,
        nf_id="orders",
        nf_provider=provider,
        length=2,
        lifecycle=LifecycleRules(retain="keep data") if keep_orders else None,
    )
    return app


assert shape_differences(deployment_shape(shop(keep_orders=False)), deployment_shape(shop(keep_orders=True))) == []

4. Use netherframe.testing for backends and FakeCloud

Install netherframe.testing (uv add --dev netherframe.testing) to access Netherframe's extracted test harnesses under nf.testing:

  • nf.testing.graph_memory.InMemoryGraphBackend — test graph-state workflows without a PostgreSQL server.
  • nf.testing.state_backend_contract.StateBackendContract — subclass this contract suite to validate custom state backend plugins (locks, conditional writes, checkpoints, moves, removals).
  • netherframe-fakecloud pytest plugin — provides the fakecloud_account fixture for isolated local AWS accounts against a shared FakeCloud Docker container (pytest --nf-use-fakecloud).

Pass settings inside tests cleanly using nf.core.config.flags (with flags(...):) and silence noisy logs with nf.core.logging.logging_disabled().