|
| 1 | +--- |
| 2 | +title: What is a Golden Scene? |
| 3 | +navOrder: 10 |
| 4 | +--- |
| 5 | +Golden scenes are one of `flutter_test_golden`'s major innovations. A Golden Scene |
| 6 | +is a single image file that contains any number of individual golden images within it. |
| 7 | + |
| 8 | +> Note: If you're familiar with `golden_toolkit` you might think that Golden Scenes are just |
| 9 | +> another name for `golden_toolkit` `GoldenBuilder`s, which have existed for years. This isn't the |
| 10 | +> case. We address this in its own section below. |
| 11 | +
|
| 12 | +Historically, Flutter paints a single golden image to a file. One file means one golden, |
| 13 | +and one golden means one file. One file per golden is very cumbersome when working with |
| 14 | +a large number of golden images - especially when multiple goldens are related, such as |
| 15 | +different visual states of the same widget. |
| 16 | + |
| 17 | +A Golden Scene with independent golden images, such as different configurations of the same |
| 18 | +widget, is called a [Gallery](/golden-scenes/gallery). |
| 19 | + |
| 20 | +A Golden Scene with golden images that take place over time, such as the idle, hovered, and |
| 21 | +pressed state of a button, is called a [Film Strip](/golden-scenes/filmstrip). |
| 22 | + |
| 23 | +## What makes Golden Scenes different? |
| 24 | +Fans of golden tests are no doubt familiar with `golden_toolkit`, a package by eBay Motors, |
| 25 | +which has long been the most popular package for writing golden tests. |
| 26 | + |
| 27 | +> Note: The `golden_toolkit` package is now discontinued, and no longer supported. |
| 28 | +
|
| 29 | +The `golden_toolkit` package included the concept of a `GoldenBuilder`, which painted multiple |
| 30 | +widget configurations to the same image file. The purpose and visual output of `golden_toolkit` |
| 31 | +`GoldenBuilder`s is similar to `flutter_test_golden` Golden Scenes, but we've taken the concept to |
| 32 | +a new level of capability and value. |
| 33 | + |
| 34 | +### Extracting Golden Images from a Scene |
| 35 | +Unlike `golden_toolkit`, `flutter_test_goldens` doesn't do a pixel comparison of an entire file. |
| 36 | +`flutter_test_goldens` tracks the position of every golden image in the Golden Scene file and |
| 37 | +extracts just the golden images for comparison. |
| 38 | + |
| 39 | +When comparing an entire file, you end up comparing decorations, too. You compare the text labels |
| 40 | +beneath each golden image. You compare borders around each golden image. But none of these decorations |
| 41 | +are relevant to your test. These decorations are for human reviewers, not for the computer that's |
| 42 | +running the comparison. `flutter_test_goldens` ignores these decorations, leaving you free to |
| 43 | +paint whatever details you want, around the golden images in the scene. |
| 44 | + |
| 45 | +### Capturing Goldens over Time |
| 46 | +`golden_toolkit` made it possible to capture multiple widget configurations in a single golden file, |
| 47 | +but each of those widget configurations were independent widget trees. There was no concept of time. |
| 48 | +What if you want to capture the idle state, the hover state, and the pressed state of the same button? |
| 49 | +`golden_toolkit` couldn't help you. |
| 50 | + |
| 51 | +`flutter_test_goldens` includes the concept of a `GoldenCamera`, which allows developers to take screenshots |
| 52 | +over a period of time. Those screenshots can then be stitched together into a Golden Scene, such as |
| 53 | +with a [`FilmStrip`](/golden-scenes/filmstrip). |
0 commit comments