Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

ashwinkey04
Copy link
Contributor

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 anything

  • If you have multiple commits please combine them into one commit by squashing them.

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()
Copy link
Collaborator

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.

Copy link
Contributor Author

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

Copy link
Collaborator

@miPlodder miPlodder Aug 29, 2020

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.

Copy link
Contributor Author

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 {
Copy link
Collaborator

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?

Copy link
Contributor Author

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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was expressoVersion already existing?

Copy link
Contributor Author

@ashwinkey04 ashwinkey04 Aug 29, 2020

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() {
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

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

@miPlodder miPlodder added GSoC'20 Google Summer Of Code 2020 code changes ready to be reviewed labels Aug 29, 2020
)
)

val passwordEditText = onView(
Copy link
Collaborator

@miPlodder miPlodder Aug 29, 2020

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.

Copy link
Contributor Author

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

@miPlodder
Copy link
Collaborator

@ashwinkey04 Do we have any progress on it?

@ashwinkey04
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GSoC'20 Google Summer Of Code 2020 code changes ready to be reviewed UI Testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants