This file contains hidden or 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
| dependencies { | |
| ... | |
| androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0' | |
| } |
This file contains hidden or 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
| @LargeTest | |
| @RunWith(AndroidJUnit4::class) | |
| class NotificationTest { | |
| @get:Rule | |
| val rule = activityScenarioRule<MainActivity>() | |
| val device = UiDevice.getInstance(getInstrumentation()) | |
| @Test |
This file contains hidden or 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
| // Implementation of custum viewAction for click() Action | |
| val noConstraintsClickAction = object : ViewAction { | |
| override fun getDescription(): String { | |
| return "noConstraintsClickAction" | |
| } | |
| override fun getConstraints(): Matcher<View> { | |
| return isEnabled() // no constraints | |
| } |
This file contains hidden or 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
| @get:Rule | |
| val rule = activityScenarioRule<MyActivity>() | |
| @Test void myTest() { | |
| val scenario = rule.getScenario(); | |
| // Your test code goes here. | |
| } |
This file contains hidden or 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
| // How to get your current Activity | |
| fun getCurrentActivity(): Activity? { | |
| var currentActivity: Activity? = null | |
| getInstrumentation().runOnMainSync { run { currentActivity = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED).elementAtOrNull(0) } } | |
| return currentActivity | |
| } | |
| // Example: how to use it | |
| assertThat(getCurrentActivity(), instanceOf(MyActivity::class.java)) |
This file contains hidden or 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
| android { | |
| defaultConfig { | |
| ... | |
| testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | |
| // The following argument makes the Android Test Orchestrator run its | |
| // "pm clear" command after each test invocation. This command ensures | |
| // that the app's state is completely cleared between tests. | |
| testInstrumentationRunnerArguments clearPackageData: 'true' | |
| } |
This file contains hidden or 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
| @Test | |
| fun `when calling loadInbox, then update inboxLiveData with empty messages list`() { | |
| val messages = emptyList<MessageEntity>() | |
| runBlocking { | |
| whenever(messagesRepository.getMessages(any(), any())).thenReturn(messages) | |
| inboxViewModel.loadInbox().join() | |
| getValue(inboxViewModel.inboxLiveData).let { | |
| assertThat(it).isEqualTo(messages) |
This file contains hidden or 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
| @Entity(tableName = "inbox", indices = [Index(value = ["uid"], unique = true)]) | |
| data class Message @JvmOverloads constructor( | |
| @PrimaryKey(autoGenerate = true) @ColumnInfo(name = _id) val id: Long?, | |
| @ColumnInfo(name = timestamp) val timestamp: Long | |
| @ColumnInfo(name = uid) val uid: Long, | |
| @ColumnInfo(name = is_read, defaultValue = "0") val isRead: Int = 0 | |
| @ColumnInfo(name = text) val text: String? | |
| ) | |
| @Database(entities = arrayOf(Message::class), version = 2) |