Skip to content
pubscout

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.

$ flutter pub add source_gen_test
Source repository

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.

  • bloc_test

    A testing library that makes it easy to test blocs and cubits.

  • autopilot

    A test driver for Flutter that exposes a JSON HTTP API for QA testing.

  • flutter_svg_test

    A testing library for finding and verifying flutter_svg images in widget tests.

Works with

Packages commonly used together with source_gen_test: ones it builds on, ones built on it, and its own family.