title: Jetpack Compose UI Testing Button onClick
body: <p>I'm trying to test how a buttonClick would change the UI.</p>
  <p>The test is setup like this:</p>
  <pre><code>composeRule.setContent {
      var i by remember { mutableStateOf(0) }
      Button(modifier = Modifier.testTag(&quot;TEST&quot;), onClick = { i++ }) {
          Text(text = i.toString())
      }
  }
  </code></pre>
  <p>And my actual test looks like this:</p>
  <pre><code>val button = composeRule.onNodeWithTag(&quot;TEST&quot;)
  
  button.assertTextEquals(&quot;0&quot;)
  button.performClick()
  button.printToLog(&quot;Test&quot;)
  button.assertTextEquals(&quot;1&quot;)
  </code></pre>
  <p>The first assertion passes, however it fails when checking that the text should equal <code>1</code>:</p>
  <pre><code>java.lang.AssertionError: Failed to assert the following: (Text + EditableText = [1])
  Semantics of the node:
  Node #2 at (l=0.0, t=66.0, r=176.0, b=165.0)px, Tag: 'TEST'
  Role = 'Button'
  Text = '[0]'
  Actions = [OnClick, GetTextLayoutResult]
  MergeDescendants = 'true'
  Selector used: (TestTag = 'TEST')
  </code></pre>
  <p>The printToLog() after the click looks like this:</p>
  <pre><code>Printing with useUnmergedTree = 'false'
  Node #2 at (l=0.0, t=66.0, r=176.0, b=165.0)px, Tag: 'TEST'
  Role = 'Button'
  Text = '[0]'
  Actions = [OnClick, GetTextLayoutResult]
  MergeDescendants = 'true'
  </code></pre>
  <p>So it appears that when the click is performed, either the content is not recomposed, or for some reason, the click isn't actually happening.</p>
  <p>Does anyone know what might be going on here?</p>