-
Notifications
You must be signed in to change notification settings - Fork 664
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
feat: Add UI Tests for Login flow with Espresso #1545
Conversation
feat: Implement Espresso idling resource fix: Remove conflicting test fix: Disable animations in app/build.gradle fix: Perform scroll to button action to fix travis chore: Refactor variables in LoginSetPasscodeTest.kt
@@ -88,6 +89,7 @@ class LoginActivity : BaseActivity(), LoginView { | |||
* Starts [PassCodeActivity] | |||
*/ | |||
override fun showPassCodeActivity() { | |||
EspressoIdlingResouce.decrement() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think, for writing integration tests or be it unit test we will have to make changes in the testing classes, check on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using EspressoIdlingResource
demands production-level code be altered for letting Espresso know that the UI is being updated due to a task. This is preferred over sleeping the thread in the test resource. More information is available in the documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we making an actual API call, during the Integration test? If yes, let's not do it.
We can mock the API call, with some hardcoded JSONs, check on the feasibility of the solution which I'm referring to in this comment?
Else we can go with this approach EspressoIdlingResource
also. Moreover, we need to add EspressoIdlingResource
at Service level, just before the call increment it, and inside success
method or failure
method decrement it, adding it to UI level will involve lots of cases that needs to be taken care of.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will check for the feasibility and update on it sooner. Meanwhile, I will mark this PR as a draft
@@ -68,6 +68,9 @@ android { | |||
androidExtensions { | |||
experimental = true | |||
} | |||
testOptions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did this change fix the Travis build issue, if yes then please share the reference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a recommended practice to disable animations in the device for testing. It is also mentioned here in the documentation for espresso
@@ -140,6 +143,9 @@ dependencies { | |||
//TableView | |||
implementation "com.evrencoskun.library:tableview:$rootProject.tableViewVersion" | |||
|
|||
//Espresso Idling Resource | |||
implementation "androidx.test.espresso:espresso-idling-resource:$rootProject.espressoVersion" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was expressoVersion
already existing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The test implementation was also previously mentioned here
} | ||
|
||
@Test | ||
fun loginSetPasscodeTest() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it an integration test for a single flow, clarify. If not split it multiple flows into multiple tests, instead of covering all flows in a single test method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is meant to cover the login flow completely. So I have included steps to set passcode too so that the complete flow is covered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
Let's go with a failure case, where login is a failure. Invalid creds
Suggested naming convention, add suffix _validCreds
and _invalidCreds
. You can keep the prefix same for both the test methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, will make those changes
) | ||
) | ||
|
||
val passwordEditText = onView( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's follow convention, don't add a new line after every variable creation or after every operation. Let's add lines as a delimiter for better readability, add them wisely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look into those and remove them
@ashwinkey04 Do we have any progress on it? |
I was able to set up a mock web server using a library from OkHttp. But it was possible to place only a single API call using that. I'll need to figure something out to mock all the APIs used in the app |
Uses the espresso library to perform UI tests for complete login flow
Steps implemented:
Enter username: ashwinr
Enter password: password
Tap password visibility toggle twice
Press login button
Wait for login request to complete (Uses
CountingIdlingResource
)Checks if passcode activity layout is properly loaded and displayed
Tap password visibility toggle
Perform swipe up action to make the digit 0 and proceed buttons visible in smaller devices (Required for Travis CI to pass)
Tap digit 0 four times (To input passcode as 0000)
Press proceed button
Perform passcode input again
Press save button
Apply the
AndroidStyle.xml
style template to your code in Android Studio.Run the unit tests with
./gradlew check
to make sure you didn't break anythingIf you have multiple commits please combine them into one commit by squashing them.