Flutter integration_test - add --flavor argument in VS Code
Asked Answered
W

1

6

I have a suite of integration tests for a Flutter app. I would like to run them using the VS Code Testing tab, so that I can easily see info about what tests passed/failed, etc.

VS Code Testing View

This worked fine before we implemented flavors. Now that flavors are defined in launch.json, running the tests require a --flavor argument, but I can't seem to set that in the UI.

If I try to run them on iOS using the Testing tab in VS Code, I get this error:

The Xcode project defines schemes: dev, prod, qa Exception: You must specify a --flavor option to select one of the available schemes.

I can run flutter test integration_test --flavor dev, but the terminal fills up with logs and it's harder to find out which tests failed and why.

Weanling answered 1/12, 2022 at 20:37 Comment(2)
What version of Flutter do you use? There was an issue with flavors but that has actually been fixed some time ago.Trueblood
@Trueblood I'm currently using Flutter version 3.7.6 and am still experiencing this issue.Weanling
L
1

I just struggled with it too. You need to add this in your launch.json:

{
        "name": "integration test",
        "request": "launch",
        "type": "dart",
        // Define your flavor (here: foo) that you use in tests
        "toolArgs": [
            "--flavor",
            "foo",
        ],
        // This is important: set it only for integration_test
        "templateFor": "integration_test",
    },

Thats it! Now you can run them on VSCode too.

Libbielibbna answered 21/12, 2023 at 14:8 Comment(1)
This only works if you want to run all tests at once - the Run/Debug buttons next to each test will still fail.Ytterbia

© 2022 - 2024 — McMap. All rights reserved.