1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

FlutterのテストをGitHub Actionsで実行する

Posted at

はじめに

こんにちは、エンジニアのkeitaMaxです。
Flutterで書いたテストをGitHub Actionsで実行できるようにしてみます。

GitHub Actionsの作成

.github/workflows/unittest.ymlファイルを作成します。

subosito/flutter-actioというActionを使用します。

今回は静的解析flutter analyzeとユニットテストflutter testを実行したいので、以下のようにymlファイルを作成しました。

unittest.yml
name: Flutter CI

on: [pull_request]

jobs:
  analyze_and_test:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v6

      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        with:
          channel: stable
          flutter-version: '3.35.5'

      - name: Flutter pub get
        run: flutter pub get

      - name: Run static analysis
        run: flutter analyze

      - name: Run unit tests
        run: flutter test

以下はPRにPushされたタイミングでActionsが動くように設定しています

on: [pull_request]

以下でflutterのバージョンを指定したり準備をしています。

      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        with:
          channel: stable
          flutter-version: '3.35.5'

以下ではライブラリをインストールしています。

      - name: Flutter pub get
        run: flutter pub get

以下で静的解析を行なっています。

      - name: Run static analysis
        run: flutter analyze

以下でユニットテストを行なっています。

      - name: Run unit tests
        run: flutter test

これでGitHub Actinosのymlファイルの作成が終わりました。

Actionの実行

PRを作成しPushしてみましょう。

すると以下のように上でActionが実行中であることが確認できます。

スクリーンショット 2025-11-30 11.36.20.png

これをクリックすると、以下のように実行していることを確認することができます。

スクリーンショット 2025-11-30 11.37.25.png

しばらく待つとすべて完了します。

テストがすべて成功すると以下のようにチェックがつきます。

スクリーンショット 2025-11-30 11.41.49.png

これでFlutterのテストをGitHub Actionsで実行することができました。

おわりに

この記事での質問や、間違っている、もっといい方法があるといったご意見などありましたらご指摘していただけると幸いです。

最後まで読んでいただきありがとうございました!

参考

次の記事

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?