Skip to content

gmockのマッチャーをプリコンパイル済みヘッダーでまとめてusingする#2101

Merged
berryzplus merged 2 commits into
sakura-editor:masterfrom
berryzplus:feature/use_gmock_matchers
Jul 13, 2025
Merged

gmockのマッチャーをプリコンパイル済みヘッダーでまとめてusingする#2101
berryzplus merged 2 commits into
sakura-editor:masterfrom
berryzplus:feature/use_gmock_matchers

Conversation

@berryzplus

Copy link
Copy Markdown
Contributor

PR対象

  • テストコード

カテゴリ

  • 改善

PR の背景

プロジェクトのテストアサーションの書き方に微妙に統一感がない。

従来の書き方例

    ASSERT_STREQ(expected, actuial);

GMockの定義済みマッチャー群をまとめて using することにより、統一感および書きやすさの向上を図ります。

仕様・動作説明

  • Pull Request 自体は using の追加のみなので、直接の影響はありません。

変更後の書き方例

    EXPECT_THAT(actuial, StrEq(expected));

PR の影響範囲

  • using追加のみなので、影響はありません。

テスト内容

  • using追加のみなので、テストできる変更がありません。
  • テスト実行結果による評価は不可能です。

関連 issue, PR

参考資料

@m-tmatma

Copy link
Copy Markdown
Member

変更後の書き方 の場合何がメリットあるんですか?
従来の書き方 の場合の問題点がわかってないです。

@berryzplus

Copy link
Copy Markdown
Contributor Author

変更後の書き方 の場合何がメリットあるんですか? 従来の書き方 の場合の問題点がわかってないです。

EXPECT_THATは「actual が expected である」をチェックします。
今回のPull Requestでは「expected である」の詳細を指定する述語関数の「::testing::」を省略できるようにしています。

こういうテストを書きたいときに便利です。
image

次のような、必ず失敗するテストケースがあるとします。

	EXPECT_STREQ( L"expected", L"actuial" );
	EXPECT_THAT( L"actuial", ::testing::StrEq(L"expected") );

実行結果はこんな感じになります。

#1 - Expected equality of these values:
  L"expected"
  L"actuial"
#2 - Value of: L"actuial"
Expected: is equal to L"expected"
  Actual: L"actuial" (of type wchar_t const [8])

従来の書き方「EXPECT_EQ」だと与えた2つの引数が意味付けされません。(どちらが結果でどちらが期待値かわからない。)

後者のほうが分かりやすいと思いますが、いかがでしょうか。

@sonarqubecloud

sonarqubecloud Bot commented Jul 6, 2025

Copy link
Copy Markdown

@m-tmatma m-tmatma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

意図を理解しました

@berryzplus

Copy link
Copy Markdown
Contributor Author

レビューありがとうございます。

マージは2approveされた時点、または、最初のapproveから1週間経過後でやっているのでしばらくお待ちください。。

@berryzplus berryzplus merged commit afb6899 into sakura-editor:master Jul 13, 2025
15 checks passed
@berryzplus berryzplus deleted the feature/use_gmock_matchers branch July 13, 2025 06:54
@beru beru added the UnitTest label Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants