【发布时间】:2021-07-22 07:18:41
【问题描述】:
所以我最近想在我的应用程序中添加一些集成测试,并遵循 flutter.dev 关于集成测试的官方指南。我设法运行了一个测试,所以我想添加另一个测试,这就是问题的开始。
我不知道如何在同一运行中添加另一个测试套件,所以类似于
测试 1:
- 点击按钮
- 检查计数器是否增加
测试2:
- 再次点击按钮
- 检查计数器是否再次增加
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('Integration test', () {
testWidgets('test 1', (WidgetTester tester) async {
app.main();
await tester.pumpAndSettle();
// doing stuff here works
});
});
}
这就是我现在的工作。我预计将 app.main() 调用移到 group 之前并简单地添加另一个 testWidgets 调用将起作用(类似于单元测试),但它没有:
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
// app.main(); <<--- moving here...
group('Integration test', () {
// app.main(); <<--- ... or here didn't help
testWidgets('test 1', (WidgetTester tester) async {
// do stuff
});
testWidgets('test 2', (WidgetTester tester) async {
// how to add this? And do stuff with the same app session
});
});
}
编辑: 为了更好地说明我想要实现的目标。以下是我目前进行的一些颤振驱动程序测试。我只想迁移到 integration_test 包的新 api,而不会丢失名称“test 1”、“test 2”等
void main() {
group("group name", () {
FlutterDriver driver;
setUpAll(() async {
driver = await FlutterDriver.connect();
});
tearDownAll(() async {
if (driver != null) {
await driver.close();
}
});
test('test 1', () async {
// do stuff with the driver
});
test('test 2', () async {
// do other stuff with the driver with the same seesion
});
test('test 3', () async {
// etc
});
});
}
【问题讨论】: