build_test 3.3.4
build_test: ^3.3.4 copied to clipboard
Utilities for writing unit tests of Builders.
Questions? Suggestions? Found a bug? Please file an issue or start a discussion.
Test helpers for build_runner builders.
In-memory builds #
The testBuilders method provides a way to run builds in
memory for small, self contained tests. See the test
folder in the build
package for examples.
In-memory builds with real sources #
To pass sources on disk to testBuilders
, create a
TestReaderWriter.
You can write individual sources to it from a
PackageAssetReader, or write all sources to it with
loadIsolateSources
:
final readerWriter = TestReaderWriter(rootPackage: 'test_package');
await readerWriter.testing.loadIsolateSources();
testBuilder(
yourBuilder,
{'test_package|lib/a.dart': '''
import 'package:real_package/annotations.dart';
@RealAnnotation()
class TestClass {}
'''},
readerWriter: readerWriter,
);
Resolving source code #
Use resolveAsset or resolveSource to resolve code with the analyzer:
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);
});