| name | widget-tester-scaffolder |
| description | Automatically generates a baseline Widget Test file for a given UI screen, wrapping it in a MaterialApp to prevent context errors. |
Instructions
When the developer asks to test a widget or screen (e.g., "Create a test for the LoginScreen"):
- Create a corresponding test file in the
test/ directory matching the source path.
- Scaffold a basic
testWidgets block.
- Critically, always wrap the target widget in a
MaterialApp and a Scaffold (if it doesn't already have one) when calling tester.pumpWidget() to avoid "No Material widget found" or "No MediaQuery found" errors.
Example Template:
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
// Import the widget to test here
void main() {
testWidgets('Renders MyWidget correctly', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: MyWidget(),
),
),
);
// Add expectations here
expect(find.byType(MyWidget), findsOneWidget);
});
}
Inform the user where the test was created and remind them to add their specific mock dependencies or expectations.