首页 > 解决方案 > Flutter 在 Android Studio 中运行多个单元测试

问题描述

我一直在关注这个 Flutter 文档: https ://flutter.dev/docs/cookbook/testing/unit/introduction

如果我打开文件并通过点击运行按钮运行它,我可以在 Android Studio 中运行测试。

问题是我想一键运行所有测试,就像在 Xcode 中一样。

如何在 Android Studio 中做到这一点?

我做了什么:

创建了两个愚蠢的测试,只是为了拥有它们。

在此处输入图像描述

使用选项创建测试配置All in Directory并指向测试目录:

在此处输入图像描述

在点击播放按钮后,我得到:

Failed to load "/Users/martinberger/Dev/flutter_apps/iCash/icash/test/second_test.dart":
Test never connected to test harness.
Test: /Users/martinberger/Dev/flutter_apps/iCash/icash/test/second_test.dart
Shell: /Users/martinberger/Dev/flutter/bin/cache/artifacts/engine/darwin-x64/flutter_tester

所以第一个测试完成了,但是下一个,甚至没有开始。

在我读过的十几个教程/博客/文档中,他们都专注于编写一个测试并通过右键单击或打开它并单击“播放”按钮来运行它。

我来自 iOS/Xcode 背景,所以在 Android Studio 中运行一个简单的测试套件有什么我应该知道的吗?

标签: android-studiofluttertesting

解决方案


您可以flutter test在终端中键入,然后键入您想要的目录。

所以在你的情况下:flutter test test/


推荐阅读