Testing utility class to help you synthesize stacks and assert on the generated Terraform JSON.
The Testing Class
TheTesting class is the primary entry point for writing tests in tfts. It provides methods for creating test applications, synthesizing stacks, and performing assertions.
Testing.app()
Creates a newApp instance configured for testing.
Testing.synth()
Synthesizes a stack into a JSON object that can be used for assertions.Testing.synthScope()
A helper method that creates a temporary scope, executes a callback to define resources, and returns the synthesized JSON.Testing.synthToJson()
Synthesizes a stack and returns the result as a formatted JSON string.Testing.renderConstructTree()
Returns a visual representation of the construct tree, which is useful for debugging complex hierarchies.Assertions
tfts provides several assertion methods to verify the contents of the synthesized Terraform JSON.Testing.toHaveResource()
Asserts that the JSON contains a resource of a specific type. You can optionally provide properties to match.Testing.toHaveResourceWithProperties()
Similar totoHaveResource, but specifically emphasizes checking for a set of properties.
Testing.toHaveDataSource()
Asserts that the JSON contains a data source of a specific type.Testing.toHaveProvider()
Asserts that the JSON contains a provider configuration.Example Test File
Here is a complete example of a test file usingbun:test.