expector 0.1.4 copy "expector: ^0.1.4" to clipboard
expector: ^0.1.4 copied to clipboard

A package to write tests in a fluent manner and more easily.

Expector #

Build Status

This package provides a way to write tests more easily in a fluent manner (with content assists).

Instead of writing expect(value, and provide a matcher to check the value, just type expectThat(value). and let the content assist do its job!

Usage #

A simple usage example:

import 'package:expector/expector.dart';
import 'package:test/test.dart';

String? f() => 'hello';

void main() {
  test('f() returns a 5-length string', () {
    expectThat(f()).isNotNull
      ..isNotEmpty
      ..hasLength(5);
  });
}

What's the problem with test package ? #

The test package allows users to describe expectations with matchers: expect(value, matcher). Unfortunatelly there are a lot of matchers and it's easy to use a matcher that has no meaning regarding the value tested. In this case, there will be no error at compile time but there will be a runtime error. For instance:

import 'package:test/test.dart';

String? f() => 'hello';

void main() {
  test('f() returns a 5-length string', () {
    expect(f(), isNotNull);
    expect(f(), isNotEmpty);
    expect(f(), hasLength(5));
    expect(f(), isNaN); // no compile time
  });
}

Another issue is that there is no content assist to help user. Everything is suitable as matcher and it could be hard to find the good one.

License #

Apache 2.0

4
likes
160
points
106
downloads

Publisher

unverified uploader

Weekly Downloads

A package to write tests in a fluent manner and more easily.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

meta, test

More

Packages that depend on expector