Skip to content

Commit 391d371

Browse files
[Docs] - Document golden test runners
1 parent 1d83588 commit 391d371

File tree

4 files changed

+109
-1
lines changed

4 files changed

+109
-1
lines changed

doc/website/source/_data.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
website:
2+
social:
3+
opengraph:
4+
url: https://fluttergoldens.com
5+
title: Flutter Test Goldens
6+
description: The best package for writing golden tests.
7+
image: https://fluttergoldens.com/images/branding/social.png
8+
type: website
9+
10+
twitter:
11+
card: summary_large_image
12+
site: "@SuprDeclarative"
13+
url: https://fluttergoldens.com
14+
title: Flutter Test Goldens
15+
description: The best package for writing golden tests.
16+
image: https://fluttergoldens.com/images/branding/social.png
17+
118
# Configuration for the package that this website documents.
219
package:
320
name: flutter_test_goldens
@@ -37,6 +54,10 @@ navigation:
3754
- title: "Get Started"
3855
url: /get-started
3956

57+
- title: Create a Test
58+
tag: create-a-test
59+
sortBy: navOrder
60+
4061
- title: Galleries
4162
tag: gallery
4263
sortBy: navOrder
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tags: create-a-test
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: Test Runners
3+
---
4+
Test runners are the methods that are used to declare and define tests. Typically,
5+
golden tests are defined with the `testWidgets()` test runner. However, `flutter_test_goldens`
6+
comes with its own test runners for convenience, e.g., `testGoldenScene()`.
7+
8+
## The Standard Test Runner
9+
The standard test runner in `flutter_test_goldens` is `testGoldenScene()`.
10+
11+
```dart
12+
void main() {
13+
testGoldenScene("my golden test", (tester) async {
14+
// TODO: implement golden test.
15+
});
16+
}
17+
```
18+
19+
The `testGoldenScene()` test runner wraps around Flutter's standard `testWidgets()`
20+
test runner, while making a few adjustments:
21+
22+
* Sets the `devicePixelRatio` to `1.0` to unify all test pixel densities, and reduce scaling artifacts.
23+
* Sets the `textScaleFactor` to `1.0` to unify all test text scales, and reduce scaling artifacts.
24+
* Loads app fonts so that labels and decorations around your goldens are rendered with a real font.
25+
26+
27+
## Platform Specific Test Runners
28+
When writing golden tests, sometimes you may want to simulate a specific platform. For example, maybe
29+
you want to render a golden of your app with an iOS style UI, specifically. For this purpose,
30+
`flutter_test_goldens` provides per-platform test runners.
31+
32+
```dart
33+
void main() {
34+
testGoldenSceneOnIOS("my iOS golden test", (tester) async {
35+
// TODO: implement golden test.
36+
});
37+
38+
testGoldenSceneOnAndroid("my Android golden test", (tester) async {
39+
// TODO: implement golden test.
40+
});
41+
42+
testGoldenSceneOnMac("my Mac golden test", (tester) async {
43+
// TODO: implement golden test.
44+
});
45+
46+
testGoldenSceneOnWindow("my Windows golden test", (tester) async {
47+
// TODO: implement golden test.
48+
});
49+
50+
testGoldenSceneOnLinux("my Linux golden test", (tester) async {
51+
// TODO: implement golden test.
52+
});
53+
}
54+
```
55+
56+
The implementation of the platform-specific test runners are nearly identical to `testGoldenScene()`, except
57+
they set the `debugDefaultTargetPlatformOverride` property to the given platform.
58+
59+
```dart
60+
debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
61+
```
62+
63+
When the test completes, `debugDefaultTargetPlatformOverride` is reset to `null`.
64+
65+
You could implement this behavior yourself, within the standard `testWidgets()` runner, but
66+
these platform-specific test runners are provided as a convenient way to simulate a platform without
67+
repeating the platform configuration every time.
68+

doc/website/source/get-started.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
---
22
title: Get Started
33
---
4+
## Add the Package
45
To get started with `flutter_test_goldens`, add the package to your pubspec.
56

67
```yaml
78
dev_dependencies:
89
flutter_test_goldens: any
910
```
1011
11-
With the packaged added, you may want to accomplish a variety of goals:
12+
## Start a Test
13+
Define a test using the `testGoldenScene()` method, or a related test runner.
14+
15+
```dart
16+
void main() {
17+
testGoldenScene("my golden test", (tester) async {
18+
// TODO: implement golden test.
19+
});
20+
}
21+
```
22+
23+
Using `flutter_test_goldens` test runners isn't strictly required, but they handle some test
24+
configuration that's expected for a golden test.
25+
26+
[Learn more](/create-a-test/test-runners) about `flutter_test_goldens` test runners.
27+
28+
## Implement a Test
29+
With a test ready to go, you may want to accomplish a variety of goals:
1230

1331
* [Write a gallery test](/golden-scenes/gallery)
1432
* [Write a timeline test](/golden-scenes/filmstrip)

0 commit comments

Comments
 (0)