unit-testing - 如何使用 pub run test 运行特定的 Dart _test 文件?

标签 unit-testing testing dart

我的 test_dir 中有一堆文件,问题是它们必须单独运行,因为其中一个是测试只能在浏览器中运行的代码,另一个是测试只能运行的代码在后端。

现在,我知道 pub run test 有一个 -n 参数用于指定测试名称,但我如何运行特定文件?文档中不是很清楚,我无法成功完成。

最佳答案

您可以只添加目录或具体文件名

pub run test test/some_dir/some_file_test.dart

如果您只想在控制台或浏览器中运行某些测试,您可以针对每个测试或每个文件进行配置,或者在项目配置文件中进行配置。

Some test files only make sense to run on particular platforms. They may use dart:html or dart:io, they might test Windows' particular filesystem behavior, or they might use a feature that's only available in Chrome. The @TestOn annotation makes it easy to declare exactly which platforms a test file should run on. Just put it at the top of your file, before any library or import declarations:

@TestOn("vm") // or @TestOn("browser")

import "dart:io";

import "package:test/test.dart";

void main() {
  // ...
}

当你像这样运行所有测试时

pub run test -pchrome -pfirefox -pie

那么这个测试将不会运行,因为没有包含-pvm

这允许像这样的细粒度配置

For example, if you wanted to run a test on every browser but Chrome, you would write @TestOn("browser && !chrome").

测试包很好README对于所有其他配置选项。

关于unit-testing - 如何使用 pub run test 运行特定的 Dart _test 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37035574/

相关文章:

python - 如何模拟 celery 任务的类方法

linux - 是否可以在 Linux 上运行 Magento TAF(测试自动化框架)?

firebase - 对于与用户uid相同的文档ID,如何从Firestore中仅检索一个用户的数据?

flutter - Flutter:如何在带有动画的ListView中移动到最后一个位置

ios - Collection View 流布局上的 estimatedItemSize 导致单元测试崩溃 - EXC_ARITHMETIC

c# - 使用返回随机结果的函数进行单元测试

java - 如何对调用 super 的重写方法进行单元测试?

ruby-on-rails - 什么样的行为应该成为测试的对象?

在两个独立的 Angular 应用程序之间切换时,AngularJS e2e 测试挂起

flutter - 如何在if(登录帐户Firebase) flutter 的情况下更改抽屉滑轨