-
Notifications
You must be signed in to change notification settings - Fork 514
Fixing tests #398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fixing tests #398
Changes from 1 commit
b0c5ef5
2a4fe7b
2868494
b338bbc
d79a161
4a4661f
762661e
0265f6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package com.example.android.pip | ||
|
|
||
| import android.view.View | ||
| import android.widget.TextView | ||
| import androidx.test.core.app.ActivityScenario.launch | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import androidx.test.filters.LargeTest | ||
| import com.google.common.truth.Truth.assertThat | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| @LargeTest | ||
| class PiPSampleActivityTest { | ||
|
|
||
| /** | ||
| * Verifies that the timer starts and updates the time. | ||
| */ | ||
| @Test | ||
| fun startTimer_updatesTime() { | ||
| val scenario = launch(PiPSampleActivity::class.java) | ||
|
|
||
| scenario.onActivity { activity -> | ||
| val startBtn = activity.findViewById<View>(R.id.start_or_pause) | ||
| val timeText = activity.findViewById<TextView>(R.id.time) | ||
|
|
||
| // Initial state | ||
| assertThat(timeText.text.toString()).isEqualTo("00:00:00") | ||
|
|
||
| // Start timer | ||
| startBtn.performClick() | ||
| } | ||
|
|
||
| // Wait for async update | ||
| Thread.sleep(1500) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please fix |
||
|
|
||
| scenario.onActivity { activity -> | ||
| val timeText = activity.findViewById<TextView>(R.id.time) | ||
|
|
||
| // Time should now be updated | ||
| assertThat(timeText.text.toString()).isNotEqualTo("00:00:00") | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Verifies that the Clear button resets the timer. | ||
| */ | ||
| @Test | ||
| fun clearTimer_resetsTime() { | ||
| val scenario = launch(PiPSampleActivity::class.java) | ||
|
|
||
| scenario.onActivity { activity -> | ||
| val startBtn = activity.findViewById<View>(R.id.start_or_pause) | ||
| val clearBtn = activity.findViewById<View>(R.id.clear) | ||
| val timeText = activity.findViewById<TextView>(R.id.time) | ||
|
|
||
| startBtn.performClick() | ||
| clearBtn.performClick() | ||
|
|
||
| // Time should reset | ||
| assertThat(timeText.text.toString()).isEqualTo("00:00:00") | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test has a potential race condition. It clicks 'start' and then 'clear' immediately within the same UI thread task. This doesn't guarantee that the timer has actually started counting before it's cleared. To make this test more robust, you should first verify that the timer is running and then test the clear functionality. The suggested change refactors the test to wait for the timer to start before clearing it. Note that
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please fix |
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.