Skip to content

Instantly share code, notes, and snippets.

@Sprajapati123
Created July 16, 2025 15:00
Show Gist options
  • Save Sprajapati123/7b5706842db71d7e3b30aa2d74f26ccb to your computer and use it in GitHub Desktop.
Save Sprajapati123/7b5706842db71d7e3b30aa2d74f26ccb to your computer and use it in GitHub Desktop.
package com.example.ai36
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextInput
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.example.ai36.view.LoginActivity
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class LoginActivityTest {
@get:Rule
val composeRule = createAndroidComposeRule<LoginActivity>()
@Test
fun testSuccessfulLogin_navigatesToDashboard() {
// Enter email
composeRule.onNodeWithTag("email")
.performTextInput("[email protected]")
// Enter password
composeRule.onNodeWithTag("password")
.performTextInput("password")
// Click Login
composeRule.onNodeWithTag("button")
.performClick()
// You can now verify if DashboardActivity is launched.
// Basic workaround (check for no errors):
composeRule.waitForIdle()
}
@Test
fun testEmptyEmail_ShowsNoNavigation() {
composeRule.onNodeWithTag("button")
.performClick()
// Expect no crash or stay on same screen
composeRule.waitForIdle()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment