Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widget testing TestFailure on version 5.0.0-release-candidate-9.2.1 #3244

Open
feriyalsusanto opened this issue Oct 23, 2024 · 1 comment
Open
Assignees

Comments

@feriyalsusanto
Copy link

feriyalsusanto commented Oct 23, 2024

Widget testing using latest version 5.0.0-release-candidate-9.2.1 always not found

test_page.dart

import 'package:flutter/material.dart';

class TestPage extends StatefulWidget {
  const TestPage({super.key});

  @override
  State<TestPage> createState() => _TestPageState();
}

class _TestPageState extends State<TestPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Test Page')),
      body: Padding(
        padding: const EdgeInsets.all(16),
        child: Column(
          children: [TextButton(key: const ValueKey('btn_submit'),
            onPressed: () {}, child: const Text('SUBMIT'))],
        ),
      ),
    );
  }
}

widget_test.dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';
import 'package:test_app/test_page.dart';

void main() {
  testWidgets('Find Button in Test Page', (WidgetTester tester) async {
    await tester.pumpWidget(const GetMaterialApp(home: TestPage()));

    var button = find.byKey(const ValueKey('btn_submit'));
    expect(button, findsOneWidget);
  });
}

Result

00:07 +0: Find Button in Test Page
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure was thrown running a test:
Expected: exactly one matching candidate
  Actual: _KeyWidgetFinder:<Found 0 widgets with key [<'btn_submit'>]: []>
   Which: means none were found but one was expected

When the exception was thrown, this was the stack:
#4      main.<anonymous closure> (file:///D:/Workspace/Appium/test-app/test_app/test/widget_test.dart:18:5)
<asynchronous suspension>
#5      testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:189:15)
<asynchronous suspension>
#6      TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:1032: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:/Workspace/Appium/test-app/test_app/test/widget_test.dart line 18
The test description was:
  Find Button in Test Page
════════════════════════════════════════════════════════════════════════════════════════════════════
00:07 +0 -1: Find Button in Test Page [E]
  Test failed. See exception logs above.
  The test description was: Find Button in Test Page

But, if I using version 4.6.6, the test is passed.

@feriyalsusanto feriyalsusanto changed the title Widget testing TestFailure on version 5.0.0-release-candidate-6 Widget testing TestFailure on version 5.0.0-release-candidate-9.2.1 Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@feriyalsusanto @jonataslaw and others