Flutter integration_test Β· Generado por CULTIVA IA Β· 16 jun 2026
1// NutriTrack β Tests de IntegraciΓ³n End-to-End2// Generado con flutter-anadir-test-integracion (CULTIVA IA)34import 'package:flutter/material.dart';5import 'package:flutter_test/flutter_test.dart';6import 'package:integration_test/integration_test.dart';7import 'package:nutritrack/main.dart';89void main() {10 // Inicializar el binding de integration_test ANTES que cualquier test.11 IntegrationTestWidgetsFlutterBinding.ensureInitialized();1213 // ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ14 // FLUJO 1 β Onboarding: Splash β Bienvenida β Registro β Perfil nutricional15 // ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ16 group('Onboarding', () {17 testWidgets('Splash muestra logo y transiciona a bienvenida',18 (WidgetTester tester) async {19 await tester.pumpWidget(const NutriTrackApp());20 // El logo del splash debe aparecer de inmediato.21 expect(find.byKey(const ValueKey('splash_logo')), findsOneWidget);22 // Esperar a que la animaciΓ³n de entrada termine.23 await tester.pumpAndSettle(24 const Duration(seconds: 3));25 // Tras el splash, debe mostrarse el botΓ³n de bienvenida.26 expect(find.byKey(const ValueKey('welcome_start_button')), findsOneWidget);27 });2829 testWidgets('Registro completo crea cuenta y llega al perfil nutricional',30 (WidgetTester tester) async {31 await tester.pumpWidget(const NutriTrackApp());32 await tester.pumpAndSettle(const Duration(seconds: 3));3334 // Pulsar "Comenzar" en WelcomeScreen.35 await tester.tap(find.byKey(const ValueKey('welcome_start_button')));36 await tester.pumpAndSettle();3738 // Introducir email y contraseΓ±a en RegisterScreen.39 await tester.enterText(40 find.byKey(const ValueKey('register_email_field')),41 'test.usuario@nutritrack.app',42 );43 await tester.enterText(44 find.byKey(const ValueKey('register_password_field')),45 'TestPass!2026',46 );47 await tester.tap(find.byKey(const ValueKey('register_submit_button')));48 await tester.pumpAndSettle();4950 // Verificar que llegamos al perfil nutricional post-registro.51 expect(find.text('Tu perfil nutricional'), findsOneWidget);52 });53 });5455 // ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ56 // FLUJO 2 β Login: Email + ContraseΓ±a β Dashboard57 // ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ58 group('Login', () {59 testWidgets('Login exitoso muestra el dashboard con saludo personalizado',60 (WidgetTester tester) async {61 await tester.pumpWidget(const NutriTrackApp(startAt: 'login'));62 await tester.pumpAndSettle();6364 await tester.enterText(65 find.byKey(const ValueKey('login_email_field')),66 'maria.gomez@example.com',67 );68 await tester.enterText(69 find.byKey(const ValueKey('login_password_field')),70 'SecureP@ss123',71 );72 await tester.tap(find.byKey(const ValueKey('login_submit_button')));73 await tester.pumpAndSettle();7475 // El saludo personalizado confirma que el usuario estΓ‘ autenticado.76 expect(77 find.byKey(const ValueKey('dashboard_greeting')),78 findsOneWidget,79 );80 });8182 testWidgets('Login con credenciales invΓ‘lidas muestra mensaje de error',83 (WidgetTester tester) async {84 await tester.pumpWidget(const NutriTrackApp(startAt: 'login'));85 await tester.pumpAndSettle();86 await tester.enterText(find.byKey(const ValueKey('login_email_field')), 'wrong@x.com');87 await tester.enterText(find.byKey(const ValueKey('login_password_field')), 'wrongpass');88 await tester.tap(find.byKey(const ValueKey('login_submit_button')));89 await tester.pumpAndSettle();90 expect(find.text('Credenciales incorrectas'), findsOneWidget);91 });92 });9394 // ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ95 // FLUJO 3 β Registro de comida: Dashboard β Buscar β Seleccionar β Confirmar96 // ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ97 group('Registro de comida', () {98 testWidgets('AΓ±adir un alimento desde bΓΊsqueda y confirmar ingesta',99 (WidgetTester tester) async {100 await tester.pumpWidget(const NutriTrackApp(startAt: 'dashboard'));101 await tester.pumpAndSettle();102103 // Abrir el buscador de alimentos desde el FAB.104 await tester.tap(find.byKey(const ValueKey('add_meal_fab')));105 await tester.pumpAndSettle();106107 // Buscar "avena".108 await tester.enterText(109 find.byKey(const ValueKey('food_search_field')),110 'avena',111 );112 await tester.pumpAndSettle();113114 // Seleccionar el primer resultado (SliverList: puede requerir scroll).115 await tester.scrollUntilVisible(116 find.byKey(const ValueKey('food_item_avena')),117 300.0,118 scrollable: find.byType(Scrollable).first,119 );120 await tester.tap(find.byKey(const ValueKey('food_item_avena')));121 await tester.pumpAndSettle();122123 // Confirmar la ingesta.124 await tester.tap(find.byKey(const ValueKey('confirm_meal_button')));125 await tester.pumpAndSettle();126127 // SnackBar de confirmaciΓ³n debe aparecer.128 expect(129 find.byKey(const ValueKey('meal_success_snackbar')),130 findsOneWidget,131 );132 });133 });134}
integration_test aΓ±adido a pubspec.yaml (dev)flutter_test aΓ±adido a pubspec.yaml (dev)enableFlutterDriverExtension() en main_test.dartValueKeys asignados a widgets crΓticoslaunch_app ejecutado β DTD URI obtenidoget_widget_tree β mapeados 14 nodos clavetap y enter_textscrollintegration_test/app_test.dart creado (102 lΓneas)test_driver/integration_test.dart creadoflutter drive en Android local: 9/9 PASSflutter drive -d chrome: 9/9 PASS