0Pricing
Jetpack Compose Academy · レッスン

アサーションとアクションの実行

状態を検証し、ユーザー入力をシミュレートします。

「アサーションとアクションの実行」はCoddyKit上の無料Jetpack Compose Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはJetpack Compose Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Jetpack Compose Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Find, Then Verify

Finding a node is only half the job. To prove your UI behaves, you add an assertion that states what should be true about that node. ✅

assertIsDisplayed

The most common assertion is assertIsDisplayed. It confirms the node is actually visible to the user, not just present in the tree.

composeTestRule.onNodeWithText("Welcome")
    .assertIsDisplayed()

assertExists vs assertIsDisplayed

Watch the difference: assertExists checks the node is in the tree, while assertIsDisplayed also checks it is on screen and not clipped away.

composeTestRule.onNodeWithText("Footer")
    .assertExists()

Chaining Assertions

You can chain several checks on one node. Each returns the node again, so the test reads like a clear sentence about your UI state.

rule.onNodeWithText("Save")
    .assertIsDisplayed()
    .assertIsEnabled()

Performing a Click

To simulate a tap, call performClick on a found node. Compose dispatches the same click your real users would trigger.

composeTestRule.onNodeWithText("Add")
    .performClick()

Typing Text

For input fields, performTextInput types characters into the focused field, letting you test forms exactly as a user would fill them.

rule.onNodeWithText("Email")
    .performTextInput("a@b.com")

Act, Then Assert

The classic flow is act then assert: perform a click, then verify the new state appeared. This mirrors how a person uses your app.

rule.onNodeWithText("+").performClick()
rule.onNodeWithText("Count: 1")
    .assertIsDisplayed()

Asserting on State Flags

Beyond visibility, you can check toggles. assertIsOn and assertIsOff verify switches and checkboxes hold the value you expect.

rule.onNodeWithText("Notifications")
    .assertIsOff()

Quick Check

You want to confirm a button is genuinely on screen, not merely present in the tree. Which assertion do you use?

Assert on Count

When you grab a group with onAllNodes, verify how many matched using assertCountEquals. It is perfect for checking list sizes.

rule.onAllNodesWithText("Item")
    .assertCountEquals(3)

Clear Before You Type

Replacing text? Call performTextClearance first, then performTextInput, so old characters do not stick around and break your check.

rule.onNodeWithText("Name")
    .performTextClearance()

Readable, Trustworthy Tests

Good assertions describe behavior, not pixels. Aim for tests that read like requirements, so a failure instantly tells you what behavior broke.

Recap: Actions & Assertions

You drive the UI with actions like performClick and performTextInput, then prove the result with assertions like assertIsDisplayed. That is the heart of UI testing. 🎯

よくある質問

「アサーションとアクションの実行」レッスンは無料ですか?

はい。「アサーションとアクションの実行」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Jetpack Compose Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Jetpack Compose Academyコースには全4レッスンが含まれています。

「アサーションとアクションの実行」で何を学びますか?

状態を検証し、ユーザー入力をシミュレートします。 ブラウザで直接実行するハンズオンコードでJetpack Compose Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Jetpack Compose Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのJetpack Compose Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。

「アサーションとアクションの実行」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このJetpack Compose Academyレッスンでコードを書いて実行できますか?

はい。すべてのJetpack Compose Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. createComposeRuleとFinder
  2. アサーションとアクションの実行
  3. セマンティクスとテストタグ
  4. ViewModelとFlowのテスト
← Jetpack Compose Academyに戻る