|
| 1 | +--- |
| 2 | +title: Running on GitHub |
| 3 | +description: How to run and manage golden tests on GitHub CI. |
| 4 | +navOrder: 10 |
| 5 | +--- |
| 6 | +GitHub is the most popular place to run tests, including golden tests, because its |
| 7 | +free, and GitHub is the place where almost everyone hosts their source code and |
| 8 | +reviews pull requests (PRs). |
| 9 | + |
| 10 | +## Run Golden Tests on GitHub |
| 11 | +The following YAML configuration shows how to run Flutter golden tests in a GitHub |
| 12 | +Runner. This particular example is configured to run on every PR, but you can adjust |
| 13 | +it for other use-cases. Place this configuration in your project at `.github/workflows/pr_validation.yaml`. |
| 14 | + |
| 15 | +```yaml |
| 16 | +name: PR Validation |
| 17 | +on: |
| 18 | + pull_request: |
| 19 | + |
| 20 | +jobs: |
| 21 | + test_goldens: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + # Checkout the repository. |
| 25 | + - uses: actions/checkout@v3 |
| 26 | + |
| 27 | + # Setup Flutter environment. |
| 28 | + - uses: subosito/flutter-action@v2 |
| 29 | + with: |
| 30 | + channel: "stable" |
| 31 | + |
| 32 | + # Download all the packages that the app uses. |
| 33 | + - run: flutter pub get |
| 34 | + |
| 35 | + # Run all golden tests (change for whatever directory you use). |
| 36 | + - run: flutter test test_goldens |
| 37 | +``` |
| 38 | +
|
| 39 | +## Download Failures from GitHub |
| 40 | +By default, when running golden tests on GitHub CI, you can only see the terminal |
| 41 | +output for failures. It's often very helpful to be able to see the actual Failure |
| 42 | +Scenes, so that you can understand why your local tests passed, but GitHub failed. |
| 43 | +
|
| 44 | +To be able to download Failure Scene images, you must configure GitHub CI to upload |
| 45 | +those images within the job. |
| 46 | +
|
| 47 | +Assuming that all of your failure are stored within subdirectories called `failures`, |
| 48 | +adjust your GitHub CI configuration to place the following step at the end of your |
| 49 | +job. This typically follows immediately after `- run: flutter test test_goldens`. |
| 50 | + |
| 51 | +```yaml |
| 52 | +# Archive golden failures |
| 53 | +- uses: actions/upload-artifact@v4 |
| 54 | + if: failure() |
| 55 | + with: |
| 56 | + name: golden-failures |
| 57 | + path: "**/failures/**/*.png" |
| 58 | +``` |
| 59 | + |
| 60 | +Adjust the `path` for wherever/however you choose to store your failure images. |
0 commit comments