hegeltest_flutter 0.5.0 copy "hegeltest_flutter: ^0.5.0" to clipboard
hegeltest_flutter: ^0.5.0 copied to clipboard

Flutter integration for hegeltest — property-based testing powered by Hegel's native engine. Use with flutter_test instead of package:test.

hegeltest_flutter — Property-based testing for Flutter #

pub package CI license

Flutter integration for hegeltest — property-based testing powered by Hegel's native fuzzing engine.

Why this package? #

hegeltest depends on package:test. Flutter projects use flutter_test. This package bridges the gap by providing hegelFlutterTest() which uses flutter_test's test() function while giving you full access to all hegeltest generators.

Quick Start #

dev_dependencies:
  hegeltest_flutter: ^0.3.0
  flutter_test:
    sdk: flutter
import 'package:flutter_test/flutter_test.dart';
import 'package:hegeltest_flutter/hegeltest_flutter.dart';

void main() {
  hegelFlutterTest('reverse is involutory', (tc) {
    final xs = tc.draw(lists(integers()));
    expect(xs.reversed.toList().reversed.toList(), equals(xs));
  });
}

Run with:

flutter test

API #

hegelFlutterTest() accepts all the same parameters as hegelTest():

  • testCases — number of random inputs to try (default: 100)
  • seed — fixed seed for reproducibility
  • reproduce — replay a specific failure blob
  • config — HegelConfig for reusable settings
  • setUpEach / tearDownEach — per-iteration lifecycle hooks
  • All flutter_test parameters: timeout, tags, skip, retry

All generators from package:hegeltest are re-exported:

  • Primitives: integers(), doubles(), booleans(), bigIntegers()
  • Text: text(), fromRegex(), emails(), urls(), uuids()
  • Collections: lists(), sets(), maps()
  • Combinators: oneOf(), sampled(), nullable(), tuples2/3/4()
  • Temporal: dates(), times(), dateTimes()
  • Network: ipv4Addresses(), ipv6Addresses()
  • Bytes: bytes()

Stateful Testing #

For complex, state-dependent systems, hegeltest_flutter supports stateful property-based testing. This allows you to generate random sequences of operations and verify that your system invariants hold at every step.

import 'package:hegeltest_flutter/hegeltest_flutter.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  hegelFlutterStatefulTest('counter works', () => CounterMachine());
}

Widget Testing #

hegeltest_flutter includes hegelFlutterWidgetTest which wraps testWidgets(), allowing you to run property-based tests on your Flutter UI. The callback receives both a TestCase (for drawing random values) and a WidgetTester (for pumping widgets).

Basic example: generating random text and verifying it renders.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hegeltest_flutter/hegeltest_flutter.dart';

void main() {
  hegelFlutterWidgetTest('text widget renders correctly', (tc, tester) async {
    final text = tc.draw(strings());
    await tester.pumpWidget(MaterialApp(home: Text(text)));
    expect(find.text(text), findsOneWidget);
  });
}

Config sweep example: generate random widget configs, pump, and verify no overflow.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hegeltest_flutter/hegeltest_flutter.dart';

void main() {
  hegelFlutterWidgetTest('padding does not cause overflow', (tc, tester) async {
    final left = tc.draw(integers(min: 0, max: 100)).toDouble();
    final top = tc.draw(integers(min: 0, max: 100)).toDouble();
    final right = tc.draw(integers(min: 0, max: 100)).toDouble();
    final bottom = tc.draw(integers(min: 0, max: 100)).toDouble();

    await tester.pumpWidget(
      MaterialApp(
        home: Center(
          child: Padding(
            padding: EdgeInsets.fromLTRB(left, top, right, bottom),
            child: const SizedBox(width: 50, height: 50),
          ),
        ),
      ),
    );
    
    expect(find.byType(SizedBox), findsOneWidget);
  });
}

Platform Support #

Platform Status
macOS arm64 ✅
Linux x64 ✅
Linux arm64 ✅
Windows x64 ✅
Windows arm64 ✅
Web ❌ (throws UnsupportedError)

License #

MIT. See LICENSE.

0
likes
0
points
320
downloads

Publisher

verified publisherletstesttools.dev

Weekly Downloads

Flutter integration for hegeltest — property-based testing powered by Hegel's native engine. Use with flutter_test instead of package:test.

Homepage
Repository (GitHub)
View/report issues

Topics

#testing #property-based-testing #fuzzing #flutter

License

unknown (license)

Dependencies

flutter, flutter_test, hegeltest

More

Packages that depend on hegeltest_flutter