-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Update Tests for better Resource Idling
Removing all the `Thread.sleep()` in favor of Compose "waitUntil()" for better handling idling resources. The solution here is based on the excellent article from Jose Alcérreca. https://medium.com/androiddevelopers/alternatives-to-idling-resources-in-compose-tests-8ae71f9fc473
- Loading branch information
1 parent
5688f39
commit 2772cff
Showing
5 changed files
with
49 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
libraries/test/src/main/java/com/escodro/test/ComposeContentTestRuleExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.escodro.test | ||
|
||
import androidx.compose.ui.test.SemanticsMatcher | ||
import androidx.compose.ui.test.junit4.ComposeContentTestRule | ||
|
||
/** | ||
* Waits until the given matcher satisfied or until the [timeoutMillis] is reached. | ||
* | ||
* See: https://medium.com/androiddevelopers/alternatives-to-idling-resources-in-compose-tests-8ae71f9fc473 | ||
*/ | ||
fun ComposeContentTestRule.waitUntilExists( | ||
matcher: SemanticsMatcher, | ||
timeoutMillis: Long = 3_000L | ||
) = waitUntilNodeCount(matcher = matcher, count = 1, timeoutMillis = timeoutMillis) | ||
|
||
fun ComposeContentTestRule.waitUntilNotExists( | ||
matcher: SemanticsMatcher, | ||
timeoutMillis: Long = 3_000L | ||
) = waitUntilNodeCount(matcher = matcher, count = 0, timeoutMillis = timeoutMillis) | ||
|
||
private fun ComposeContentTestRule.waitUntilNodeCount( | ||
matcher: SemanticsMatcher, | ||
count: Int, | ||
timeoutMillis: Long = 3_000L | ||
) = waitUntil(timeoutMillis) { | ||
onAllNodes(matcher).fetchSemanticsNodes().size == count | ||
} |