widget_test.dart에서 오류가 납니다
조회수 525회
안녕하세요 막 공부를 시작한 학생입니다. 코드를 받아서 실행해보려했는데 widget_test.dart의 expect(find.text('0'), findsOneWidget);에서 오류가 납니다. 다른 해결법을 검색해봐도 잘 모르겠어서 올려봅니다
widget_test.dart
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:myApp_frontend/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const myApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}
main.dart
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:get/get.dart';
import 'package:myApp_frontend/Pages/native_lang_select_page.dart';
import 'package:myApp_frontend/controller/my_country_currency_controller.dart';
import 'package:myApp_frontend/controller/travel_controller.dart';
import 'package:myApp_frontend/pages/home_page.dart';
import 'package:myApp_frontend/style.dart';
void main() async {
await dotenv.load(fileName: 'assets/config/.env');
runApp(const myApp());
}
class myApp extends StatelessWidget {
const myApp({super.key});
@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'myApp',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: AppColor.background),
useMaterial3: true,
),
home: const CheckStorage(),
);
}
}
class CheckStorage extends StatefulWidget {
const CheckStorage({Key? key}) : super(key: key);
@override
CheckStorageState createState() => CheckStorageState();
}
class CheckStorageState extends State<CheckStorage> {
late FlutterSecureStorage secureStorage;
@override
void initState() {
super.initState();
secureStorage = const FlutterSecureStorage();
_checkAndNavigate();
}
@override
void dispose() {
MyCountryCurrencyController().dispose();
super.dispose();
}
Future<void> _checkAndNavigate() async {
String? myCountry = await secureStorage.read(key: 'country');
String? myCurrency = await secureStorage.read(key: 'currency');
String? travelLanguage = await secureStorage.read(key: 'travelLanguage');
String? travelCurrency = await secureStorage.read(key: 'travelCurrency');
if (myCountry != null && myCurrency != null) {
final controller = Get.put(MyCountryCurrencyController());
controller.modify(myCountry, myCurrency);
if (travelLanguage != null) {
final travelController = Get.put(TravelController());
travelController.modify(travelLanguage, travelCurrency!);
}
Get.off(() => const HomePage());
} else {
Get.off(() => const NativeLanguageSelect(fromHomeScreen: false));
}
}
@override
Widget build(BuildContext context) {
return const Scaffold(
body: Center(
child: Text('hello'),
),
);
}
}
Test Results
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure was thrown running a test:
Expected: exactly one matching candidate
Actual: _TextWidgetFinder:<Found 0 widgets with text "0": []>
Which: means none were found but one was expected
When the exception was thrown, this was the stack:
#4 main.<anonymous closure> (file:///D:/test/myApp-FE-main/test/widget_test.dart:18:5)
<asynchronous suspension>
#5 testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:183:15)
<asynchronous suspension>
#6 TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:1017:5)
<asynchronous suspension>
<asynchronous suspension>
(elided one frame from package:stack_trace)
This was caught by the test expectation on the following line:
file:///D:/test/myApp-FE-main/test/widget_test.dart line 18
The test description was:
Counter increments smoke test
════════════════════════════════════════════════════════════════════════════════════════════════════
Test failed. See exception logs above.
The test description was: Counter increments smoke test
댓글 입력