2022年5月6日金曜日

Compose のテストで No compose hierarchies found in the app エラーがでた場合

次のような Compose のテストを実行したときに
  1. class ComposeTest {  
  2.   
  3.     @get:Rule  
  4.     val composeTestRule = createComposeRule()  
  5.   
  6.     @Test  
  7.     fun myTest() {  
  8.         composeTestRule.setContent {  
  9.             Text("Hello")  
  10.         }  
  11.   
  12.         composeTestRule.onNodeWithText("Hello").assertIsDisplayed()  
  13.     }  
  14. }  

java.lang.IllegalStateException: No compose views found in the app. Is your Activity resumed?

(1.1 系)


java.lang.IllegalStateException: No compose hierarchies found in the app. Possible reasons include: (1) the Activity that calls setContent did not launch; (2) setContent was not called; (3) setContent was called before the ComposeTestRule ran. If setContent is called by the Activity, make sure the Activity is launched after the ComposeTestRule runs

(1.2 系)

というエラーがでる場合、テストを実行しているエミュレータやデバイスの画面が off になっていないかチェックしましょう。

0 件のコメント:

コメントを投稿