|
1 | | -This library provides some utilities for unit testing `Builder`s. |
| 1 | +# build_test |
2 | 2 |
|
3 | | -See the `test` folder in the `build` package for examples. |
| 3 | +Testing utilities for users of [`package:build`][]. |
| 4 | + |
| 5 | +<p align="center"> |
| 6 | + <a href="https://travis-ci.org/dart-lang/build"> |
| 7 | + <img src="https://travis-ci.org/dart-lang/build.svg?branch=master" alt="Build Status" /> |
| 8 | + </a> |
| 9 | + <a href="https://github.com/dart-lang/build/labels/package%3Abuild_test"> |
| 10 | + <img src="https://img.shields.io/github/issues-raw/dart-lang/build/package%3Abuild_test.svg" alt="Issues related to build_test" /> |
| 11 | + </a> |
| 12 | + <a href="https://pub.dartlang.org/packages/build_test"> |
| 13 | + <img src="https://img.shields.io/pub/v/build_test.svg" alt="Pub Package Version" /> |
| 14 | + </a> |
| 15 | + <a href="https://www.dartdocs.org/documentation/build_test/latest"> |
| 16 | + <img src="https://img.shields.io/badge/dartdocs-latest-blue.svg" alt="Latest Dartdocs" /> |
| 17 | + </a> |
| 18 | + <a href="https://gitter.im/dart-lang/source_gen"> |
| 19 | + <img src="https://badges.gitter.im/dart-lang/source_gen.svg" alt="Join the chat on Gitter" /> |
| 20 | + </a> |
| 21 | +</p> |
| 22 | + |
| 23 | +## Installation |
| 24 | + |
| 25 | +This package is intended to only be as a [development dependency][] for users |
| 26 | +of [`package:build`][], and should not be used in any production code. Simply |
| 27 | +add to your `pubspec.yaml`: |
| 28 | + |
| 29 | +```yaml |
| 30 | +dev_dependencies: |
| 31 | + build_test: |
| 32 | +``` |
| 33 | +
|
| 34 | +## Usage |
| 35 | +
|
| 36 | +_See the `test` folder in the `build` package for more examples_. |
| 37 | + |
| 38 | +### Resolve source code for testing |
| 39 | + |
| 40 | +Using [`resolveAsset`][api:resolveAsset] and |
| 41 | +[`resolveSource`][api:resolveSource], you can resolve Dart source code into a |
| 42 | +static element model, suitable for probing and using within tests of code you |
| 43 | +might have written for a `Builder`: |
| 44 | + |
| 45 | +```dart |
| 46 | +test('should resolve a simple dart file', () async { |
| 47 | + var resolver = await resolveSource(r''' |
| 48 | + library example; |
| 49 | +
|
| 50 | + class Foo {} |
| 51 | + '''); |
| 52 | + var libExample = resolver.getLibraryByName('example'); |
| 53 | + expect(libExample.getType('Foo'), isNotNull); |
| 54 | +}); |
| 55 | +``` |
| 56 | + |
| 57 | +### Run a `Builder` within a test environment |
| 58 | + |
| 59 | +Using [`testBuilder`][api:testBuilder], you can run a functional test of a |
| 60 | +`Builder`, including feeding specific assets, and more. It automatically |
| 61 | +creates an in-memory representation of various utility classes. |
| 62 | + |
| 63 | +### Various test implementations of classes |
| 64 | + |
| 65 | +* [`FakeWatcher`][api:FakeWatcher] |
| 66 | +* [`InMemoryAssetReader`][api:InMemoryAssetReader] |
| 67 | +* [`InMemoryAssetWriter`][api:InMemoryAssetWriter] |
| 68 | +* [`MultiAssetReader`][api:MultiAssetReader] |
| 69 | +* [`PackageAssetReader`][api:PackageAssetReader] |
| 70 | +* [`RecordingAssetWriter`][api:RecordingAssetWriter] |
| 71 | +* [`StubAssetReader`][api:StubAssetReader] |
| 72 | +* [`StubAssetWriter`][api:StubAssetWriter] |
| 73 | + |
| 74 | +[development dependency]: https://www.dartlang.org/tools/pub/dependencies#dev-dependencies |
| 75 | +[`package:build`]: https://pub.dartlang.org/packages/build |
| 76 | + |
| 77 | +[api:FakeWatcher]: https://www.dartdocs.org/documentation/build_test/latest/build_test/FakeWatcher-class.html |
| 78 | +[api:InMemoryAssetReader]: https://www.dartdocs.org/documentation/build_test/latest/build_test/InMemoryAssetReader-class.html |
| 79 | +[api:InMemoryAssetWriter]: https://www.dartdocs.org/documentation/build_test/latest/build_test/InMemoryAssetWriter-class.html |
| 80 | +[api:MultiAssetReader]: https://www.dartdocs.org/documentation/build_test/latest/build_test/MultiAssetReader-class.html |
| 81 | +[api:PackageAssetReader]: https://www.dartdocs.org/documentation/build_test/latest/build_test/PackageAssetReader-class.html |
| 82 | +[api:RecordingAssetWriter]: https://www.dartdocs.org/documentation/build_test/latest/build_test/RecordingAssetWriter-class.html |
| 83 | +[api:StubAssetReader]: https://www.dartdocs.org/documentation/build_test/latest/build_test/StubAssetReader-class.html |
| 84 | +[api:StubAssetWriter]: https://www.dartdocs.org/documentation/build_test/latest/build_test/StubAssetWriter-class.html |
| 85 | + |
| 86 | +[api:resolveAsset]: https://www.dartdocs.org/documentation/build_test/latest/build_test/resolveAsset.html |
| 87 | +[api:resolveSource]: https://www.dartdocs.org/documentation/build_test/latest/build_test/resolveSource.html |
| 88 | +[api:testBuilder]: https://www.dartdocs.org/documentation/build_test/latest/build_test/testBuilder.html |
0 commit comments