Glados<T> class

The entrypoint for Glados testing.

Usually, you directly call test on the Glados instance:

Glados<int>().test('blub', (input) { ... });

Custom generators

The generator can be used to customize how values are generated and shrunk. For example, if you test code that expects email addresses, it may be inefficient to use the default Generator for String – if the tests contain some sanity checks at the beginning, only a tiny fraction of values actually passes through the code. In that case, create a custom Generator. To do that, add an extension on Any, which is a namespace for Generators:

extension EmailAny on Any {
  Generator<String> get email => simple(
    generate: (random, size) => /* code for generating emails */,
    shrink: (input) => /* code for shrinking the given email */,
  );
}

For more ways on how to cleverly combine generators, see the built-in definitions. Then, you can use that generator like this:

Glados(any.email).test('email test', (email) { ... });

If you create a generator for a type that doesn't have a Generator yet (or you want to swap out a built-in Generator for some reason), you can set it as the default for that type:

// Use the email generator for all Strings.
Any.defaults[String] = any.email;

Then, you don't need to explicitly provide the Generator to Glados anymore. Instead, Glados will use it based on given type parameters:

// This will now use the any.email generator, because it was set as the
// default for String before.
Glados<String>().test('blub', () { ... });

If a Generator is the default Generator for a type, I recommend relying on implicit discovery, as the type parameters make the intention clearer. If you still want to provide the explore parameter, you can use null as a generator, causing Glados to look for the default Generator.

Glados<String>(null, Explore(...)).test('blub', () { ... });

Exploration

To customize the exploration phase, provide an ExploreConfig configuration. See the ExploreConfig doc comments for more information.

Constructors

Glados([Generator<T>? generator, ExploreConfig? explore])

Properties

explore ExploreConfig
final
generator Generator<T>
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
test(String description, Tester<T> body, {String? testOn, Timeout? timeout, dynamic skip, dynamic tags, Map<String, dynamic>? onPlatform, int? retry}) → void
Executes the given body with a bunch of parameters, trying to break it.
testWithRandom(String description, TesterWithRandom<T> body, {String? testOn, Timeout? timeout, dynamic skip, dynamic tags, Map<String, dynamic>? onPlatform, int? retry}) → void
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited