我的 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
ordart: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/