Skip to content

Instantly share code, notes, and snippets.

@tomaszpolanski
Last active October 5, 2020 10:13
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tomaszpolanski/69c979360d1c0c4b1ea0bac6f4bbabf6 to your computer and use it in GitHub Desktop.
Save tomaszpolanski/69c979360d1c0c4b1ea0bac6f4bbabf6 to your computer and use it in GitHub Desktop.
Golden Files testing in Flutter
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
setUp(() {
// Limits viewport in tests to size of 100, 100 to decrease the size of
// the pngs
WidgetsBinding.instance.renderView.configuration =
TestViewConfiguration(size: const Size(100, 100));
});
testWidgets('Golden file testing', (tester) async {
// RepaintBoundary is needed to optimize the png
await tester.pumpWidget(RepaintBoundary(child: MyWidget(0)));
await tester.pumpAndSettle();
await expectLater(
find.byType(RepaintBoundary),
matchesGoldenFile('golden-file.png'),
);
});
}
class MyWidget extends StatelessWidget {
const MyWidget(this.radius, {Key key}) : super(key: key);
final double radius;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8),
child: Container(
decoration: BoxDecoration(
border: Border.all(
width: 12,
color: Color(0xFF01579B),
),
borderRadius: BorderRadius.all(Radius.circular(radius)),
),
child: FlutterLogo(),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment