hegel library
Property-based testing for Dart, powered by the Hegel engine.
A property is a claim about every input, checked against inputs the engine generates. When one fails, the engine shrinks the failing case to the smallest one that still fails and remembers it, so the property keeps failing until the bug is fixed.
Classes
- Database
- Where discovered counterexamples are persisted.
-
DeferredGenerator<
T> - The generator deferred returns, before and after it is defined.
-
Generator<
T> -
A recipe for values of type
T. - Invariant
- Something that must be true between steps.
-
Pool<
T> - A set of values a stateful test made, that the engine can choose among.
- Rule
- One thing a stateful test can do.
- Settings
- Configuration for one run.
- StateMachine
- A system under test, its model, and the steps between them.
- TestCase
- One test case, as a property body sees it.
- TextGenerator
- Generates strings over an alphabet.
Enums
- Backend
- Where the engine's randomness comes from.
- HealthCheck
- A health check the engine may abort a run over.
- Mode
- Whether to run the full loop or a single test case.
- Phase
- One phase of the property-test loop.
- Verbosity
- How much the engine says while it runs.
Constants
-
everyHealthCheck
→ const Set<
HealthCheck> - Every health check, for turning the lot off.
-
everyPhase
→ const Set<
Phase> - Every phase, which is also what the engine does by default.
Functions
-
bigIntegers(
{BigInt? min, BigInt? max}) → Generator< BigInt> -
Generates integers of any width between
minandmaxinclusive. -
booleans(
{double probability = 0.5}) → Generator< bool> -
Generates true with probability
probability, false otherwise. -
bytes(
{int minLength = 0, int? maxLength}) → Generator< Uint8List> -
Generates byte strings of
minLengthtomaxLengthbytes. -
characters(
{String? codec, int? minCodepoint, int? maxCodepoint, List< String> ? categories, List<String> ? excludeCategories, String? includeCharacters, String? excludeCharacters}) → TextGenerator - Generates single characters, drawn the way text draws them.
-
composite<
T> (T build(TestCase testCase)) → Generator< T> -
Generates values
buildputs together out of draws of its own. -
dates(
{DateTime? min, DateTime? max}) → Generator< DateTime> -
Generates dates between
minandmaxinclusive. -
dateTimes(
{DateTime? min, DateTime? max}) → Generator< DateTime> -
Generates dates and times between
minandmaxinclusive. -
deferred<
T> () → DeferredGenerator< T> - A generator that stands in for one not written yet.
-
domains(
{int maxLength = 255}) → Generator< String> -
Generates fully-qualified domain names of at most
maxLengthcharacters. -
doubles(
{double min = double.negativeInfinity, double max = double.infinity, bool? allowNan, bool? allowInfinity, bool excludeMin = false, bool excludeMax = false}) → Generator< double> -
Generates doubles between
minandmax. -
durations(
{Duration? min, Duration? max}) → Generator< Duration> -
Generates durations between
minandmaxinclusive. -
emails(
) → Generator< String> - Generates email addresses, per RFC 5321 and 5322.
-
fromRegex(
String pattern, {bool fullMatch = true, TextGenerator? alphabet}) → Generator< String> -
Generates strings matching
pattern, in Pythonresyntax. -
integers(
{int? min, int? max}) → Generator< int> -
Generates integers between
minandmaxinclusive. -
ipAddresses(
{InternetAddressType? type}) → Generator< InternetAddress> -
Generates IP addresses of
type, or of either kind when none is given. -
just<
T> (T value) → Generator< T> -
Generates
valueand nothing else. -
lists<
T> (Generator< T> elements, {int minLength = 0, int? maxLength, bool unique = false}) → Generator<List< T> > -
Generates lists of what
elementsgenerates. -
maps<
K, V> (Generator< K> keys, Generator<V> values, {int minLength = 0, int? maxLength}) → Generator<Map< K, V> > -
Generates maps of what
keysandvaluesgenerate. -
oneOf<
T> (List< Generator< options, {List<T> >int> ? weights}) → Generator<T> -
Generates values from whichever of
optionseach case picks. -
optional<
T> (Generator< T> value) → Generator<T?> -
Generates values from
value, or null. -
property(
Object? description, FutureOr< void> body(TestCase), {Settings settings = const Settings(), String? reproduce, bool? printBlob, String? testOn, Timeout? timeout, Object? skip, Object? tags, Map<String, dynamic> ? onPlatform, int? retry}) → void - Registers a property as a package:test test.
-
runProperty(
FutureOr< void> body(TestCase), {Settings settings = const Settings(), String? databaseKey, String? reproduce, bool? printBlob, void onDiagnostic(String line)?}) → Future<void> -
Checks
bodyagainst test cases the engine chooses. -
runStateful(
TestCase testCase, StateMachine machine, {int minConcurrency = 1, int maxConcurrency = 1}) → Future< void> -
Runs
machineagainst test cases the engine sequences. -
sampledFrom<
T> (List< T> values) → Generator<T> -
Generates values picked from
values. -
sets<
T> (Generator< T> elements, {int minLength = 0, int? maxLength}) → Generator<Set< T> > -
Generates sets of what
elementsgenerates. -
text(
{int minLength = 0, int? maxLength, String? codec, int? minCodepoint, int? maxCodepoint, List< String> ? categories, List<String> ? excludeCategories, String? includeCharacters, String? excludeCharacters}) → TextGenerator -
Generates strings of
minLengthtomaxLengthcharacters. -
times(
{Duration? min, Duration? max}) → Generator< Duration> -
Generates times of day between
minandmaxinclusive. -
tuple2<
A, B> (Generator< A> first, Generator<B> second) → Generator<(A, B)> -
Generates pairs of what
firstandsecondgenerate. -
tuple3<
A, B, C> (Generator< A> first, Generator<B> second, Generator<C> third) → Generator<(A, B, C)> -
Generates triples of what
first,secondandthirdgenerate. -
tuple4<
A, B, C, D> (Generator< A> first, Generator<B> second, Generator<C> third, Generator<D> fourth) → Generator<(A, B, C, D)> -
Generates quadruples of what
firsttofourthgenerate. -
urls(
) → Generator< String> - Generates http and https URLs, per RFC 3986.
-
uuids(
{int? version}) → Generator< String> - Generates UUIDs in the canonical 8-4-4-4-12 form.
Exceptions / Errors
- AssumptionFailed
- Signals that an assumption did not hold, so this test case is invalid.
- PropertyError
- Raised when a run reached no verdict about the property.