Skip to content

Conversation

@harutiro
Copy link
Owner

@harutiro harutiro commented Jan 20, 2025

概要

テストを追加して、自動で、動作検証を行うように変更

関連Issue

このセクションでは、このPRが関連するIssueやタスクをリンクしてください。以下のように記述します。

変更点

このセクションでは、具体的な変更点や修正箇所を箇条書きでリストアップしてください。

  • Mockitを追加
  • GitHubのAPIを叩くRepositoryとUseCaseのテストを作成する
  • CIに追加
  • それ以外は作成しない。
    • APIの部分やViewの部分はUnitTestの範囲に含めない

テスト

このセクションでは、このPRに関連するテストケースやテスト方法を記載してください。

  • テストを走らせる

Summary by CodeRabbit

  • 新機能

    • Ktlintチェックと単体テストのための新しいGitHub Actionsワークフローを追加
    • プロジェクトの単体テストドキュメントを更新
  • テスト

    • Mockitoを使用した単体テストライブラリを追加
    • GitHubサービスのリポジトリと使用例に関する包括的な単体テストを実装
    • GitHubServiceRepositoryImplおよびGitHubServiceUsecaseImplに対する新しいテストクラスを追加
    • 単体テストのカバレッジ分析のためにJacocoプラグインを追加
  • ドキュメント

    • README.mdに単体テストの実行方法について新しいセクションを追加

@coderabbitai
Copy link

coderabbitai bot commented Jan 20, 2025

Warning

Rate limit exceeded

@harutiro has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 22 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 096b694 and f4f6332.

📒 Files selected for processing (1)
  • README.md (1 hunks)

"""

Walkthrough

このプルリクエストは、GitHub Actionsワークフロー、README、ビルド設定、およびユニットテストに関する重要な変更を導入しています。ワークフローは、Ktlintチェックとユニットテストのためのジョブを明確に分離し、README.mdにはユニットテストに関する新しいセクションが追加されました。アプリのビルド設定では、Mockitoライブラリの依存関係が追加され、GitHubサービスに関する包括的なユニットテストが実装されました。

Changes

ファイル 変更の概要
.github/workflows/check_workflow.yaml - gradleジョブをktlintにリネーム
- 新しいtestジョブの追加
README.md - "Unitテストについて"セクションの追加
app/build.gradle - Mockitoコアおよびインラインライブラリの追加
- Jacocoプラグインの追加
- Jacoco設定の追加
- jacocoTestReportタスクの登録
app/src/test/kotlin/jp/co/yumemi/android/code_check/features/github/GitHubServiceRepositoryImplTest.kt - 新しいテストクラスの追加
app/src/test/kotlin/jp/co/yumemi/android/code_check/features/github/GitHubServiceUsecaseImplTest.kt - 新しいテストクラスの追加

Sequence Diagram

sequenceDiagram
    participant Developer
    participant GitHub Actions
    participant Ktlint
    participant UnitTest
    
    Developer->>GitHub Actions: プッシュ/プルリクエスト
    GitHub Actions->>Ktlint: コードスタイルチェック
    GitHub Actions->>UnitTest: ユニットテスト実行
    Ktlint-->>GitHub Actions: チェック結果
    UnitTest-->>GitHub Actions: テスト結果
Loading

Possibly related PRs

Poem

🐰 コードの森に跳ぶ兎
テストの旅に出でたり
モックと共に踊る影
品質の道を照らす光
安心の歌を謳う夜
"""


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
app/build.gradle (1)

Line range hint 15-15: SDKバージョンとライブラリバージョンの検証が必要

以下の点について確認が必要です:

  • compileSdk 35targetSdk 35は現時点で存在しない将来のバージョンです
  • 複数のライブラリバージョンが現在リリースされている最新版より進んでいます:
    • androidx.core:core-ktx:1.15.0
    • androidx.appcompat:appcompat:1.7.0
    • その他

安定版のSDKとライブラリバージョンに修正することを推奨します。現在の安定版を確認するには、以下のコマンドを実行してください:

#!/bin/bash
# Description: Verify latest stable versions of Android SDK and libraries

# Check latest stable Android SDK version
sdkmanager --list | grep -A 5 "Installed packages:" | grep "platforms;"

# Check latest versions of androidx libraries
curl -s https://dl.google.com/dl/android/maven2/androidx/core/core-ktx/maven-metadata.xml | grep -oP "(?<=<version>)[^<]+(?=</version>)" | tail -n 1
curl -s https://dl.google.com/dl/android/maven2/androidx/appcompat/appcompat/maven-metadata.xml | grep -oP "(?<=<version>)[^<]+(?=</version>)" | tail -n 1

Also applies to: 41-50

🧹 Nitpick comments (7)
app/src/test/kotlin/jp/co/yumemi/android/code_check/features/github/GitHubServiceUsecaseImplTest.kt (2)

48-68: モックデータの構造化を推奨します

テストの可読性と再利用性を向上させるため、モックデータをコンパニオンオブジェクトまたは別のテストデータクラスに移動することを提案します。

+ companion object {
+     private fun createMockRepositoryItem(
+         name: String,
+         ownerIconUrl: String,
+         language: String,
+     ) = RepositoryItem(
+         name = name,
+         ownerIconUrl = ownerIconUrl,
+         language = language,
+         stargazersCount = 100,
+         forksCount = 50,
+         openIssuesCount = 30,
+         watchersCount = 70,
+     )
+ }

31-43: エッジケースのテストを追加することを推奨します

現在のテストケースは基本的なシナリオのみをカバーしています。以下のようなエッジケースのテストを追加することを推奨します:

  • 空文字列での検索
  • 特殊文字を含む検索クエリ
  • 検索結果が0件の場合
app/src/test/kotlin/jp/co/yumemi/android/code_check/features/github/GitHubServiceRepositoryImplTest.kt (2)

30-46: 成功ケースのアサーションを強化することを推奨します

現在のテストでは基本的なフィールドのみを検証しています。以下のような追加のアサーションを推奨します:

  • 言語フィールドの検証
  • Star数、Watcher数、Fork数、Issue数の検証
  • 2番目のアイテムの検証

99-124: モックデータ生成関数の改善を推奨します

モックデータ生成をより柔軟にするため、以下の改善を提案します:

  • パラメータ化されたファクトリメソッドの作成
  • テストデータのバリエーションの追加
- private fun mockRepositoryList(): RepositoryList {
+ private fun mockRepositoryList(
+     itemCount: Int = 2,
+     baseStarCount: Int = 100
+ ): RepositoryList {
.github/workflows/check_workflow.yaml (1)

18-30: テストワークフローの強化を推奨します

以下の機能を追加することで、テストの可視性と品質管理を向上させることができます:

  • テスト結果のGitHubアクションへの報告
  • テストカバレッジレポートの生成と保存
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup Gradle
        uses: gradle/gradle-build-action@v2

      - name: Change Permission
        run: chmod +x ./gradlew

      - name: Execute Unit Tests
-       run: ./gradlew test
+       run: ./gradlew test jacocoTestReport

+     - name: Upload Test Results
+       uses: actions/upload-artifact@v4
+       if: always()
+       with:
+         name: test-results
+         path: app/build/test-results
+
+     - name: Upload Coverage Report
+       uses: actions/upload-artifact@v4
+       with:
+         name: coverage-report
+         path: app/build/reports/jacoco
README.md (1)

42-52: テストドキュメントの拡充を推奨します

ユニットテストのセクションに以下の情報を追加することを推奨します:

  • テストの方針と戦略
  • カバレッジの要件
  • テストの構成ガイドライン
  • モックの使用方針
 ### Unitテストについて

 - Hilt, JUnit, Mockitoを持ちいてUnitテストを作成しました。
+
+#### テスト方針
+- ビジネスロジックは100%のカバレッジを目指す
+- リポジトリレイヤーは主要なエラーケースを網羅
+- UIレイヤーはクリティカルなユーザーフローのみテスト
+
+#### テストの構成
+- テストクラスは対象クラスと同じパッケージに配置
+- テストメソッド名は`given_when_then`形式で記述
+- モックは必要最小限に留める
app/build.gradle (1)

69-71: Mockitoの依存関係の追加を承認

テスト実装のためのMockito依存関係の追加は適切です。ただし、以下の改善を提案します:

  • mockito-coreとmockito-inlineのバージョンを揃えることで、互換性の問題を防ぐことができます
  • 最新の安定版を使用することを推奨します
-    testImplementation "org.mockito:mockito-core:4.6.1"
-    testImplementation 'org.mockito:mockito-inline:5.2.0'
+    testImplementation "org.mockito:mockito-core:5.2.0"
+    testImplementation 'org.mockito:mockito-inline:5.2.0'
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9e10989 and 1649323.

📒 Files selected for processing (5)
  • .github/workflows/check_workflow.yaml (2 hunks)
  • README.md (1 hunks)
  • app/build.gradle (1 hunks)
  • app/src/test/kotlin/jp/co/yumemi/android/code_check/features/github/GitHubServiceRepositoryImplTest.kt (1 hunks)
  • app/src/test/kotlin/jp/co/yumemi/android/code_check/features/github/GitHubServiceUsecaseImplTest.kt (1 hunks)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
.github/workflows/check_workflow.yaml (2)

18-43: テストジョブの実装について改善の提案があります。

現在の実装は良い基盤となっていますが、以下の改善を推奨します:

  1. ktlintジョブとの依存関係を設定することで、コードスタイルチェック後にテストを実行する
  2. GitHub ActionsのTest Report機能を活用してテスト結果を可視化する
  3. コードカバレッジの最低閾値を設定する

以下の変更を提案します:

  test:
    runs-on: ubuntu-latest
+   needs: ktlint
    steps:
      - uses: actions/checkout@v4

      - name: Setup Gradle
        uses: gradle/gradle-build-action@v2

      - name: Change Permission
        run: chmod +x ./gradlew

      - name: Execute Unit Tests
        run: ./gradlew test jacocoTestReport

+     - name: Publish Test Report
+       uses: mikepenz/action-junit-report@v4
+       if: always()
+       with:
+         report_paths: 'app/build/test-results/test/TEST-*.xml'

      - name: Upload Test Results
        uses: actions/upload-artifact@v4
        if: always()
        with:
          name: test-results
          path: app/build/test-results

      - name: Upload Coverage Report
        uses: actions/upload-artifact@v4
        with:
          name: coverage-report
          path: app/build/reports/jacoco

+     - name: Check Coverage
+       run: |
+         MIN_COVERAGE=80
+         COVERAGE=$(./gradlew jacocoTestCoverageVerification)
+         if [ $? -ne 0 ]; then
+           echo "コードカバレッジが${MIN_COVERAGE}%未満です"
+           exit 1
+         fi

1-3: ワークフロー全体の設定について改善を提案します。

タイムアウトと同時実行の制限を追加することで、より堅牢なワークフローになります:

 name: Run Gradle on PRs
 on: pull_request
+concurrency:
+  group: ${{ github.workflow }}-${{ github.ref }}
+  cancel-in-progress: true
 jobs:

また、各ジョブにtimeout-minutesを設定することを推奨します:

   ktlint:
     runs-on: ubuntu-latest
+    timeout-minutes: 10
     steps:

   test:
     runs-on: ubuntu-latest
+    timeout-minutes: 15
     steps:
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1649323 and 7af8d38.

📒 Files selected for processing (2)
  • .github/workflows/check_workflow.yaml (2 hunks)
  • app/build.gradle (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/build.gradle
🔇 Additional comments (1)
.github/workflows/check_workflow.yaml (1)

Line range hint 4-17: ジョブ名とステップ名の変更が適切です!

ジョブ名をgradleからktlintに変更したことで、このジョブの目的がより明確になりました。また、実行ステップの名前も具体的になり、メンテナンス性が向上しています。

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
app/build.gradle (2)

89-92: コメントアウトされたコードは削除することを推奨します

不要なコメントアウトされたコードは、可読性を低下させる可能性があります。必要ない場合は削除することをお勧めします。


102-104: ファイルフィルターの拡張を推奨します

現在のファイルフィルターに以下を追加することを検討してください:

  • Daggerが生成するコード
  • Hiltが生成するコード
  • データバインディングが生成するコード
-    def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*']
+    def fileFilter = [
+        '**/R.class',
+        '**/R$*.class',
+        '**/BuildConfig.*',
+        '**/Manifest*.*',
+        '**/*Test*.*',
+        '**/Hilt_*.*',
+        '**/*_Factory.*',
+        '**/*_MembersInjector.*',
+        '**/DataBinding*.*'
+    ]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7af8d38 and cc2f09a.

📒 Files selected for processing (2)
  • .github/workflows/check_workflow.yaml (2 hunks)
  • app/build.gradle (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/check_workflow.yaml
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (3)
app/build.gradle (3)

9-9: コードカバレッジ計測のためのJacocoプラグインが適切に追加されています!


70-71: Mockitoの依存関係が適切に追加されています!

mockito-coreとmockito-inlineの両方が追加されており、Kotlinでのモックテストに必要な設定が完了しています。


Line range hint 43-54: 依存関係のバージョン番号の確認が必要です

以下の依存関係のバージョン番号が現在利用可能なものより高くなっています:

  • androidx.core:core-ktx:1.15.0
  • androidx.appcompat:appcompat:1.7.0
  • androidx.constraintlayout:constraintlayout:2.2.0
  • androidx.recyclerview:recyclerview:1.4.0
  • androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.7
  • androidx.navigation:navigation-fragment-ktx:2.8.5

これらのバージョンが実際に存在するか確認してください。

app/build.gradle Outdated
Comment on lines 106 to 107
sourceDirectories.setFrom(files([mainSrc]))
classDirectories.setFrom(files([debugTree]))
Copy link

@coderabbitai coderabbitai bot Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Kotlinのソースディレクトリの追加を推奨します

現在の設定ではJavaのソースディレクトリのみが含まれています。Kotlinのソースも含めるために、以下の修正を推奨します:

-    sourceDirectories.setFrom(files([mainSrc]))
+    sourceDirectories.setFrom(files([
+        mainSrc,
+        "$projectDir/src/main/kotlin"
+    ]))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
sourceDirectories.setFrom(files([mainSrc]))
classDirectories.setFrom(files([debugTree]))
sourceDirectories.setFrom(files([
mainSrc,
"$projectDir/src/main/kotlin"
]))
classDirectories.setFrom(files([debugTree]))

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正しました。

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harutiro ご対応ありがとうございます!変更が正しく実装されていることを確認しました。

⟦(。◝ᴗ◜。)⟧

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
app/build.gradle (2)

9-9: プラグインのバージョンを明示することを推奨します

再現性のある確実なビルドを保証するために、jacocoプラグインのバージョンを明示的に指定することをお勧めします。

-    id 'jacoco'
+    id 'jacoco' version '0.8.8'

89-92: コメントアウトされたコードの削除を推奨します

コメントアウトされたコードはリポジトリに残さず、必要な場合はGitの履歴から参照できるようにすることをお勧めします。

-//tasks.withType(Test) {
-//    useJUnitPlatform()
-//    finalizedBy(tasks.jacocoTestReport) // report is always generated after tests run
-//}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cc2f09a and 096b694.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • app/build.gradle (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • README.md
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (2)
app/build.gradle (2)

70-71: Mockitoの依存関係の追加が適切です

テスト用のMockitoライブラリの追加が適切に行われています。mockito-coreとmockito-inlineの両方が含まれており、Kotlinでのモック作成に必要な依存関係が揃っています。


94-114: Jacocoの設定が適切に構成されています

カバレッジレポートの設定が以下の点で適切に行われています:

  • JavaとKotlinの両方のソースディレクトリが含まれている
  • 不要なファイル(R.class等)が適切にフィルタリングされている
  • XMLとHTMLの両方のレポート形式が有効化されている

@harutiro harutiro merged commit 810c210 into develop Jan 20, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants