Assertions und Aktionen ausführen
Überprüfen Sie State und simulieren Sie Nutzereingaben.
Assertions und Aktionen ausführen ist eine kostenlose Jetpack Compose Academy-Lektion auf CoddyKit. Dies ist Lektion 2 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Jetpack Compose Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Jetpack Compose Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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. 🎯
Häufig gestellte Fragen
Ist die Lektion „Assertions und Aktionen ausführen“ kostenlos?
Ja — der vollständige Text von „Assertions und Aktionen ausführen“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Jetpack Compose Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Jetpack Compose Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Assertions und Aktionen ausführen“?
Überprüfen Sie State und simulieren Sie Nutzereingaben. Du übst Jetpack Compose Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Jetpack Compose Academy zu starten?
Keine Vorkenntnisse erforderlich. Jetpack Compose Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 4.
Wie lange dauert die Lektion „Assertions und Aktionen ausführen“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Jetpack Compose Academy-Lektion Code schreiben und ausführen?
Ja. Jede Jetpack Compose Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- createComposeRule und Finder
- Assertions und Aktionen ausführen
- Semantik und Test-Tags
- ViewModels und Flows testen