I'm trying to run integration tests for a Linux desktop application in a Docker container.
I have a working project, running successful integration tests on Linux device.
I created a Docker image from the following Dockerfile content:
FROM cirrusci/flutter:stable
RUN apt-get update && \
export DEBIAN_FRONTEND=noninteractive && \
apt-get -y install --no-install-recommends unzip pkg-config clang cmake ninja-build libgtk-3-dev libappindicator1 fonts-liberation gpg-agent libxi6 libgconf-2-4 && \
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - && \
sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
apt-get update && apt-get -y install google-chrome-stable && \
CHROMEVER=$(google-chrome --product-version | grep -o "[^\.]*\.[^\.]*\.[^\.]*") && \
DRIVERVER=$(curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROMEVER") && \
wget -q --continue -P /chromedriver "http://chromedriver.storage.googleapis.com/$DRIVERVER/chromedriver_linux64.zip" && \
unzip /chromedriver/chromedriver* -d /chromedriver && \
rm -rf /var/lib/apt/lists/*
ENV PATH $CHROMEDRIVER_DIR:$PATH
I'm not sure I need Chrome and Chromedriver for my usecase, but at least it's here.
When running "flutter doctor" from this image, I get:
Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel unknown, 3.3.8, on Ubuntu 22.04 LTS 5.15.0-53-generic, locale en_US.UTF-8)
! Flutter version 3.3.8 on channel unknown at /sdks/flutter
! Upstream repository unknown
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[!] Android Studio (not installed)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
! Doctor found issues in 2 categories.
which seems quite OK.
However when running my integration tests, attempting to give access to my local X server (I'm using Ubuntu 22.04 on Wayland):
docker run --rm -it -v ${PWD}:/workspace --privileged -w /workspace -e DISPLAY="unix:0" -v /tmp/.X11-unix:/tmp/.X11-unix flutter:local /bin/sh -c "flutter clean && flutter test integration_test"
The tests fail with:
Deleting build... 14ms
Deleting .dart_tool... 3ms
Deleting ephemeral... 3ms
Deleting ephemeral... 0ms
Deleting ephemeral... 0ms
Deleting .flutter-plugins-dependencies... 0ms
Deleting .flutter-plugins... 0ms
Downloading Web SDK... 1,658ms
Downloading CanvasKit... 1,084ms
Downloading linux-x64/linux-x64-flutter-gtk tools... 1,090ms
Downloading linux-x64-profile/linux-x64-flutter-gtk tools... 156ms
Downloading linux-x64-release/linux-x64-flutter-gtk tools... 124ms
Running "flutter pub get" in workspace... 1,498ms
00:00 +0: loading /workspace/integration_test/main_test.dart B00:07 +0: loading /workspace/integration_test/main_test.dart
Error waiting for a debug connection: The log reader stopped unexpectedly, or never started.
00:07 +0 -1: loading /workspace/integration_test/main_test.dart [E]
TestDeviceException(Unable to start the app on the device.)
package:flutter_tools/src/test/integration_test_device.dart 60:7 IntegrationTestTestDevice.start
To run this test again: /sdks/flutter/bin/cache/dart-sdk/bin/dart test /workspace/integration_test/main_test.dart -p vm --plain-name 'loading /workspace/integration_test/main_test.dart'
00:07 +0 -1: Some tests failed.
Adding verbose to the test does not give much better than TestDeviceException(Unable to start the app on the device.)
I tried many things but I can't get it to work, and I can't find a lot of documentation on integration tests for desktop applications on Flutter, only on web applications, which is easier with headless Chrome.
If anyone has any hint about what could be wrong, I'd love it. Otherwise, I'll make my CI/CD run in shell mode on a non-headless VM instead of Docker, which I'd prefer not to.