Created
March 13, 2023 00:33
-
-
Save yuki2021/ba6ff525b8ac7de403d4e1bc0ef78237 to your computer and use it in GitHub Desktop.
FlutterのGoldenテストの雛形
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/services.dart'; | |
import 'package:flutter_test/flutter_test.dart'; | |
// フォントの読み込み | |
Future<void> loadJapaneseFont() async { | |
TestWidgetsFlutterBinding.ensureInitialized(); | |
final binary = rootBundle.load('assets/fonts/NotoSansJP-Black.otf'); | |
final loader = FontLoader('Roboto')..addFont(binary); | |
await loader.load(); | |
} |
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_screenutil/flutter_screenutil.dart'; | |
import 'package:flutter_test/flutter_test.dart'; | |
import 'package:golden_toolkit/golden_toolkit.dart'; | |
import '../../common/common.dart'; | |
void main() { | |
late Widget testWidget; | |
// テストするスクリーンサイズ | |
var testScreenSize = Device.phone.size; | |
// 日本語フォントの読み込み | |
setUpAll(() async { | |
await loadJapaneseFont(); | |
}); | |
// 読み込み時に実行 | |
setUp(() { | |
testWidget = MaterialApp( | |
home: ScreenUtilInit( | |
designSize: testScreenSize, | |
minTextAdapt: true, | |
builder: (context, child) { | |
return Scaffold( | |
body: Container( | |
color: Colors.white, | |
child: Center( | |
child: Text( | |
'テスト', | |
style: TextStyle( | |
fontSize: 16.sp, | |
fontWeight: FontWeight.w600, | |
), | |
), | |
), | |
), | |
); | |
}, | |
), | |
); | |
}); | |
// テスト終了時に実行 | |
tearDown(() {}); | |
testGoldens('', (WidgetTester tester) async { | |
await tester.pumpWidgetBuilder( | |
testWidget, | |
surfaceSize: testScreenSize, | |
); | |
await screenMatchesGolden(tester, 'apply_complete_screen'); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment