flutter tests never ends

133 views
Skip to first unread message

Cloe Su

unread,
Jul 6, 2020, 8:08:57 AM7/6/20
to Flutter Development (flutter-dev)
Hi everyone,

I'm currently facing a non-major issue with flutter test in Android Studio.
I wrote my code for internationalization following the example here (https://resocoder.com/2019/06/01/flutter-localization-the-easy-way-internationalization-with-json/) and I wrote two tests to verify the translations. (see the two tests below)
When I'm running the two tests separately, both pass successfully but when I run both by running "Run tests in i18n_test.dart", then the first test pass successfully and the second one never ends until a run out error. 
I did flutter clean, I tried the solution by adding "await tester.runAsync(() async {". I also tried to swap the two tests but the problem is the same, the first test passes but when it comes to the second then it runs forever, no matter which test is first. 

Does anyone know how to solve this?

Here are my two tests:
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:relax/core/i18n/app_localizations.dart';
import 'package:relax/core/i18n/application.dart';

void main() {
/// Check if all translations work
for (final String language in supportedLanguages) {
testWidgets('translations exist for $language',
(WidgetTester tester) async {
final Locale locale = Locale(language);

expect(AppLocalizations.delegate.isSupported(locale), isTrue);

final AppLocalizations localizations =
await AppLocalizations.delegate.load(locale);

expect(localizations.translate('welcomeTitle'), isNotNull);
expect(localizations.translate('choresPageTitle'), isNotNull);
});
}

testWidgets('spot check translations', (WidgetTester tester) async {
AppLocalizations localizations =
await AppLocalizations.delegate.load(const Locale('en'));
print('localizations en has been loaded');
expect(localizations.translate('welcomeTitle'), 'Hello, today is');
expect(localizations.translate('choresPageTitle'), 'Chores');
print('en translation ok');

localizations =
await AppLocalizations.delegate.load(const Locale('de'));
print('localizations de has been loaded');
expect(localizations.translate('welcomeTitle'), 'Hallo, heute ist');
expect(localizations.translate('choresPageTitle'), 'Hausarbeit');
print('de translation ok');

localizations =
await AppLocalizations.delegate.load(const Locale('fr'));
print('localizations de has been loaded');
expect(localizations.translate('welcomeTitle'), 'Bonjour, aujourd\'hui c\'est le');
expect(localizations.translate('choresPageTitle'), 'Ménage');
print('fr translation ok');

});
}

Here is also the result of Flutter doctor:

[√] Flutter (Channel stable, v1.17.5, on Microsoft Windows [version 6.1.7601], locale fr-FR)
    • Flutter version 1.17.5 at D:\...\AppDev\src\flutter
    • Framework revision 8af6b2f038 (6 days ago), 2020-06-30 12:53:55 -0700
    • Engine revision ee76268252
    • Dart version 2.8.4

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at D:/.../AppDev/SDK
    • Platform android-29, build-tools 29.0.3
    • ANDROID_HOME = D:/.../AppDev/SDK
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Android Studio (version 4.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 46.0.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[!] Connected device
    ! No devices available

! Doctor found issues in 1 category. 

cloeh...@gmail.com

unread,
Sep 5, 2020, 2:51:06 PM9/5/20
to Flutter Development (flutter-dev)
Hi everyone,

I am puting up this issue again, since I'm again facing a similar issue, with another app. This case the test is working with a sqflite database. Before the last flutter update the test was passing fine, but now it keeps on running "eternally". If I run the test in Debug mode it passes but in the normal "Run" it never stops. All prints are executing (for example, if in the test I write print(result), then this print will occur). I tried to run the test using --verbose and there I find that the test "paused at  Isolate 2253258668454735 (main)". 
Since I'm a newbie in coding, could maybe someone explain why this is happening and what can I do as a workaround?

Regards,
Cloe 

Reply all
Reply to author
Forward
0 new messages