Search packages, repositories and app categories

Package detailsv1.4.2

source_gen_test

Test support for the source_gen package. Includes helpers to make it easy to validate both success and failure cases.

macOSWindowsLinux
30-day downloads
49.6K
Likes
13
Pub points
160

Install package

flutter pub add source_gen_test

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A testing utility package for source_gen that provides helpers to easily validate both successful and failed code generation scenarios. It simplifies writing tests by offering tools to assert expected outputs and handle error conditions during code generation, ensuring reliability and correctness in build-time code generation workflows. Designed to integrate seamlessly with the source_gen ecosystem, it supports testing custom generators across different platforms.

Use cases

  • Testing code generation success cases
  • Validating error handling in generators
  • Ensuring consistent output from custom builders
  • Integrating with CI/CD pipelines
  • Verifying generator behavior across platforms
  • Debugging source generation logic

Key features

  • Helpers for success and failure assertions
  • Built-in support for test-driven generator development
  • Cross-platform compatibility
  • Easy integration with source_gen
  • Robust validation of generated code
  • Supports complex test scenarios

Suitable for

  • Developers building custom source generators
  • Teams using source_gen for boilerplate automation
  • Testers validating code generation outputs
  • Projects requiring reliable build-time code generation
  • Flutter/Dart projects with extensive code generation needs

Considerations

  • Requires familiarity with source_gen framework
  • Best used in conjunction with build_runner
  • May need additional setup for complex test environments
  • Not intended for runtime testing
  • Limited to build-time code generation testing

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Pub package CI package publisher

Make it easy to test Generators derived from package:source_gen by annotating test files.

@ShouldGenerate(
  r'''
const TestClass1NameLength = 10;

const TestClass1NameLowerCase = 'testclass1';
''',
  configurations: ['default', 'no-prefix-required'],
)
@ShouldThrow(
  'Uh...',
  configurations: ['vague'],
  element: false,
)
@TestAnnotation()
class TestClass1 {}

Test against a golden output file if you also want to write tests on the output itself.

part 'goldens/testclass2.dart';

@ShouldGenerateFile(
  'goldens/testclass2.dart',
  partOfCurrent: true,
  configurations: ['default', 'no-prefix-required'],
)
@ShouldThrow(
  'Uh...',
  configurations: ['vague'],
  element: false,
)
@TestAnnotation()
class TestClass2 {}

Other helpers are also provided.

Categories

Dependencies

Dependency list 9 items

Source repository

Projects using this package