程式完成後,不管如何都要測試,unit test 、sit test 和 uat test 都要pass 才可以上架,issue 和 bug 越早被測試出來,修改成本越低呀。
在build.gradle 新增包含 UI 測試模組的依附元件
// Test rules and transitive dependencies:
androidTestImplementation("androidx.compose.ui:ui-test-junit4:$compose_version")
// Needed for createComposeRule, but not createAndroidComposeRule:
debugImplementation("androidx.compose.ui:ui-test-manifest:$compose_version")
ComposeTestRule 可以設定撰寫內容或存取活動.
在專案(androidtest)新增測試 
class MyComposeTest {
    @get:Rule
    val composeTestRule = createComposeRule()
    // use createAndroidComposeRule<YourActivity>() if you need access to
    // an activity
    @Test
    fun myTest() {
        // Start the app
        composeTestRule.setContent {
           
                Greeting("Android")
           
        }
		//動作 
        composeTestRule.onNodeWithText("Hello Android!").performClick()
		//使用 printToLog() 顯示語意樹狀結構
        composeTestRule.onRoot().printToLog("TAG")
		//比對未合併樹狀結構的節點,可以將 useUnmergedTree 設為 true
        composeTestRule.onRoot(useUnmergedTree = true).printToLog("TAG")
		//比對器
        composeTestRule.onNodeWithText("Hello Android!").assertIsDisplayed()
    }
}
測試成功
composeTestRule.onNodeWithText("Hello Android!").performClick()
    composeTestRule.onRoot().printToLog("TAG")
輸出
printToLog:
                                                                                                    Printing with useUnmergedTree = 'false'
                                                                                                    Node #1 at (l=0.0, t=36.0, r=132.0, b=65.0)px
                                                                                                     |-Node #2 at (l=0.0, t=36.0, r=132.0, b=65.0)px
                                                                                                       Text = '[Hello Android!]'
                                                                                                       Actions = [GetTextLayoutResult]
    composeTestRule.onRoot(useUnmergedTree = true).printToLog("TAG")
輸出
printToLog:
                                                                                                    Printing with useUnmergedTree = 'true'
                                                                                                    Node #1 at (l=0.0, t=36.0, r=132.0, b=65.0)px
                                                                                                     |-Node #2 at (l=0.0, t=36.0, r=132.0, b=65.0)px
                                                                                                       Text = '[Hello Android!]'
                                                                                                       Actions = [GetTextLayoutResult]
composeTestRule.onNodeWithText("Hello Android!").assertIsDisplayed()
Compose Testing 一覽表中瀏覽完整清單

https://developer.android.com/jetpack/compose/testing
Kotlin 的技術傳教士 - 范聖佑 近期也出了一本關於 Collection 的書 - Kotlin Collection 全方位解析攻略
裡面也有蠻多 operator 的介紹,歡迎大家有興趣的參考看看
https://www.tenlong.com.tw/products/9786263331136
Android Taipei Organize - 洪彥彬 (Yanbin), 終於出書了 - 從0到0.99 Android 架構開發實戰:以便利貼應用程式為例(iThome鐵人賽系列書),這本也有用compose ui 哦
https://www.tenlong.com.tw/products/9786263332577