我正在使用Android Studio 3.3.1(在Window和Ubuntu上)在Flutter中开发一个开源Android应用程序.源可在Github上获得.
该项目有一个生成覆盖率数据的测试文件,可以使用诸如Coveralls之类的工具查看该数据.这向我表明LCOV数据包含有意义的数据.
我想使用内联代码覆盖率查看,类似于其他Jetbrains工具. “ Flutter Test”类别下的运行配置可以正确识别我的测试,并能够正确运行它们.
但是,“覆盖运行”选项被禁用.我尝试了其他运行配置,例如Android JUnit,但无济于事.
我知道我可以手动创建coverage数据,但是我的目标是自动生成coverage数据,并以内联方式显示Coverage(就像Coveralls一样).
有人知道什么运行配置(如果有)可以实现此目标吗?
附带说明,我最近将Codemagic用作我的CI工具,因此Coveralls上的coverage数据已过时,但是LCOV数据有意义的观点仍然成立.我也在Intellij中尝试了类似的设置,但结果与Android Studio相同.
解决方法:
我将所有非UI代码放在另一个纯Dart程序包中,并将其添加为对Flutter项目的依赖.
对于我的项目,这还有一个优点,就是我可以与浏览器GUI(Angular Dart)共享的代码是分开的,并且不会因Flutter依赖关系而被偶然污染,从而破坏了Web项目.
在此项目中,按照以下步骤操作,我可以在IntellJ中获得覆盖率信息:
您需要“ Dart命令行应用程序” IntelliJ运行配置,而不是“ Dart测试”,“ Flutter”或“ Flutter测试”运行配置.
为了能够使用“ Dart命令行应用程序”运行配置运行测试,您可能需要安装独立的Dart SDK,然后在“偏好设置”>中选择它.语言和框架>飞镖Dart SDK路径.
测试/ all.dart
// ignore_for_file: await_only_futures
import 'dart:async';
import 'client/controller/app_controller_test.dart' as i0;
import 'client/controller/authentication_controller_test.dart' as i1;
import 'client/controller/backoffice/backoffice_controller_test.dart' as i2;
import 'client/controller/backoffice/image_reference_controller_test.dart'
as i3;
...
Future<void> main() async {
i0.main();
i1.main();
i2.main();
...
}
import 'package:path/path.dart' as path;
...
/// Generate a single Dart file that executes all tests.
/// Dart code coverage reporting still requires that.
@Task('generate test/all.dart')
Future<void> prepareCoverage() async {
final testDir = Directory('test');
final context = path.Context(style: path.Style.posix);
final testFiles = testDir
.listSync(recursive: true, followLinks: false)
.where((e) =>
FileSystemEntity.isFileSync(e.path) && e.path.endsWith('_test.dart'))
.map(
(tf) => context.normalize(path.relative(tf.path, from: testDir.path)))
.toList()
..sort();
final content = StringBuffer('''
// ignore_for_file: await_only_futures
import 'dart:async';
''');
final executions = StringBuffer();
for (var i = 0; i < testFiles.length; i++) {
final testFile = testFiles[i];
content.writeln("import '$testFile' as i$i;");
executions.writeln(' i$i.main();');
}
content
..writeln('Future<void> main() async {')
..writeln()
..writeln(executions)
..writeln('}');
File('test/all.dart').writeAsstringSync(content.toString());
PubApp.global('dart_style')
.run(['-w', '--fix']..add('test/all.dart'), script: 'format');
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。