fluttergitlabgitlab-ciflutter-testflutterdriver

Flutter integration testing and Gitlab CI/CD


I'm trying to setup CI/CD for my Flutter app using Fastlane and GitLab based on this tutorial, however I'm having some difficulty automating Flutter integration tests using Flutter driver. The problem I'm encountering is that when all tests are completed successfully, application instance keeps being alive (as in, there's no exit code), which means no further script in Gitlab stage is executed. For example, when tests fail, the message I receive is:

Unhandled exception:
Dummy exception to set exit code.
Stopping application instance.
Driver tests failed: 255 

I receive exit code 255, which I assume Gitlab Runner will recognise as fail and stop further stages (build and deploy) from being executed?

However if tests pass all I get is: 00:05 +3: All tests passed!, and application seems to be still running.

I am using tearDownAll function but it doesn't seem to help:

tearDownAll(() async {
      if (driver != null){
        await driver.close();
      }
    }); 

Adding exit(0) or exit(255) in tearDownAll does close instance correctly, however I have now way of reading if tests passed/failed so I could set exit code as 0/255. Has anyone dealt with integration testing and GitLab CI/CD before or has encountered a similar issue with Flutter Driver?


Solution

  • I have identified the problem - I was simply using setUp() instead of setUpAll() in my tests. After changing it to

    setUpAll(() async {
        driver = await FlutterDriver.connect();
    });
    

    tests are completed successfully and application instance is closed.