Last active
October 5, 2020 10:13
-
-
Save tomaszpolanski/69c979360d1c0c4b1ea0bac6f4bbabf6 to your computer and use it in GitHub Desktop.
Golden Files testing in Flutter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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