source_gen_test
1.4.2, released 5 weeks ago by kevmoo.com
Test support for package:source_gen with helpers to validate success and failure cases.
What it does
Provides test helpers like annotations (`@ShouldGenerate`, `@ShouldThrow`, `@ShouldGenerateFile`) and batch verification utilities to validate `source_gen` generators by annotating test files.
AI-written summary of version 1.4.2, based on the package's README and metadata. Report an inaccuracy
Use it when
- You are writing a custom source_gen Generator or GeneratorForAnnotation and need to test success and failure outputs
- You want to test code generation against golden output files
- You need combinatorial batch verification of AST and declaration permutations for generators
Skip it when
- You are not writing custom code generation tools
- Your project does not use source_gen
Strengths
- Simplifies testing of source_gen generators via annotations
- Supports golden file testing for generated output
- Includes combinatorial batch verification for stress-testing generators
Weaknesses
- Limited usefulness outside of developing custom code generators
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- Yes (build_runner)
- Direct dependencies
- 9
Add source_gen_test to dev_dependencies and use annotations on test classes.
@ShouldGenerate(
r'''
const TestClass1NameLength = 10;
const TestClass1NameLowerCase = 'testclass1';
''',
configurations: ['default', 'no-prefix-required'],
)
@ShouldThrow(
'Uh...',
configurations: ['vague'],
element: false,
)
@TestAnnotation()
class TestClass1 {}Alternatives
Packages that do the same job and could replace source_gen_test.
- matcher
Support for specifying test expectations via an extensible Matcher class.
83Compare - bloc_test
A testing library that makes it easy to test blocs and cubits.
82Compare - autopilot
A test driver for Flutter that exposes a JSON HTTP API for QA testing.
66Compare - flutter_svg_test
A testing library for finding and verifying flutter_svg images in widget tests.
66Compare
Works with
Packages commonly used together with source_gen_test: ones it builds on, ones built on it, and its own family.
- analyzersource_gen_test depends on itPerforms static analysis of Dart code for tool integration and embedding.
- dart_stylesource_gen_test depends on itProvides an API and CLI to format Dart source code automatically.
- testsource_gen_test depends on itA full featured library for writing and running Dart tests across platforms.
- cli_utilsource_gen_test depends on itUtilities to help build Dart command-line apps, find the SDK, and display progress.
- buildsource_gen_test depends on itPackage for authoring build_runner compatible code generators.
- source_gensource_gen_test depends on itSource code generation builders and utilities for the Dart build system.
- build_testsource_gen_test depends on itUtilities for unit testing Dart build_runner builders in memory
- build_runnerUsed togetherA build system for Dart code generation and modular compilation.