我尝试使用包coverage
从我的Angular Dart 4.0项目获取代码覆盖率。
以下步骤是我的工作流程:
pub serve test --port=8081
pub run test --pub-serve=8081 --pause-after-load
pub global run coverage:collect_coverage --port=12345 -o coverage.json
pub global run coverage:format_coverage --packages=.packages-c -i coverage.json -o coverage.report
在第5步之后,我将得到一个覆盖一些数据的coverage.json文件,但我不知道为什么覆盖率报告总是显示每个代码都被发现。
我是否使用错误的流程获取代码覆盖率?或者有更好的方法来做到这一点?
谢谢!
有我的实验代码:
experiment_component.dart
import 'package:angular/angular.dart';
@Component(
selector: 'experiment_component',
template: '<h1>{{greeting}}</h1>'
)
class ExperimentComponent {
String greeting = '';
void greet() {
greeting = 'Hello';
}
}
experiment_component_test.dart
@TestOn('browser')
@Tags(const ['aot'])
import 'package:angular/angular.dart';
import 'package:angular4_test/src/experiment_component.dart';
import 'package:angular_test/angular_test.dart';
import 'package:test/test.dart';
NgTestBed<ExperimentComponent> testBed;
NgTestFixture<ExperimentComponent> testFixture;
@AngularEntrypoint()
void main() {
tearDown(disposeAnyRunningTest);
setUp(() async {
testBed = new NgTestBed<ExperimentComponent>();
testFixture = await testBed.create();
});
test('should render Hello', () async {
await testFixture.update((comp)=> comp.greet());
expect(testFixture.text, contains('Hello'));
});
}
.packages-C
angular4_test:lib/
coverage.report
|import 'package:angular/angular.dart';
|
|@Component(
| selector: 'experiment_component',
| template: '<h1>{{greeting}}</h1>'
|)
|class ExperimentComponent {
|
| String greeting = '';
|
| void greet() {
0| greeting = 'Hello';
| }
|
|}