build_test 0.10.1+1 copy "build_test: ^0.10.1+1" to clipboard
build_test: ^0.10.1+1 copied to clipboard

outdatedDart 1 only

Utilities for writing unit tests of Builders.

build_test #

Testing utilities for users of package:build.
Build Status Issues related to build_test Pub Package Version Latest Dartdocs Join the chat on Gitter

Installation #

This package is intended to only be as a development dependency for users of package:build, and should not be used in any production code. Simply add to your pubspec.yaml:

dev_dependencies:
  build_test:

Running tests #

To run tests, you should go through the pub run build_runner test command. This will compile all your tests to a temp directory and run them using pub run test. If you would like to see the output directory, you can use the --output=<dir> option to force the output to go to a specific place.

Forwarding additional args to pub run test #

It is very common to need to pass some arguments through to the eventual call to pub run test. To do this, add all those args after an empty -- arg.

For example, to run all chrome platform tests you would do pub run build_runner test -- -p chrome.

Debugging web tests #

This package will automatically create *.debug.html files next to all your *_test.dart files, which can be loaded in a browser from the normal development server (pub run build_runner serve).

Writing tests for your custom Builder #

In addition to assiting in running normal tests, this package provides some utilities for testing your custom Builder classes.

See the test folder in the build package for more examples.

Run a Builder within a test environment #

Using testBuilder, you can run a functional test of a Builder, including feeding specific assets, and more. It automatically creates an in-memory representation of various utility classes.

Resolve source code for testing #

Using resolveAsset and resolveSource, you can resolve Dart source code into a static element model, suitable for probing and using within tests of code you might have written for a Builder:

test('should resolve a simple dart file', () async {
  var resolver = await resolveSource(r'''
    library example;

    class Foo {}
  ''');
  var libExample = resolver.getLibraryByName('example');
  expect(libExample.getType('Foo'), isNotNull);
});

Various test implementations of classes #