We were asking us the same question and were surprised to not find any examples of running native tests with flutter - as described in https://github.com/flutter/flutter/wiki/Plugin-Tests (thanks for providing the link btw).
Solution with gradle (without flutter_plugin_tools)
Assumption: the plugin structure got scaffolded by the flutter create --template=plugin --platforms=android ...
command.
To run the native tests, make sure that the local gradle property files ./example/android/local.properties
and ./android/local.properties
are created properly. This can be achieved by running flutter pub get
or flutter test
in the root directory of the plugin.
Then you're ready to run gradle --project-dir ./example/android test
, which executes the test target for all subprojects from the plugin example (which includes the effective plugin code)
Here's an example of a (slightly stripped down) github actions workflow for testing a plugin (name: plgn1
):
name: CI/CD, test code
on: [push]
jobs:
plgn1-plugin:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./app/3rdparty/plgn1
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v2
with:
java-version: "11"
distribution: "adopt"
cache: 'gradle'
- uses: subosito/flutter-action@v2
with:
flutter-version: "3.0.1"
channel: "stable"
- name: Config flutter
run: flutter config --no-analytics
- name: "Run flutter pub get"
run: flutter pub get
- name: "Run Flutter test(s)"
run: flutter test
- name: "Run Flutter test(s) for plugin example"
run: flutter test
working-directory: ./app/3rdparty/plgn1/example
- name: "Run Android test(s) for plugin example"
run: gradle --project-dir ./example/android --no-daemon test
Skipping flutter_plugin_tools (opinion, own experience)
The way how the plugin tests are described for native-tests
sounded quite easy and feasible, but after playing 1h around I lost my patience (and I eventually got the feeling that it's not designed for a flutter plugin like ours).
I skipped eventually flutter_plugin_tools
and went on with gradle
directly. That's probably not the way how it should be run in the flutter ecosystem, but it's working for us.
Please let me know when you find an easier or more elegant way to run native tests of a flutter plugin!