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

Fix ui tests and create a primitive backend mock #24

Closed
wants to merge 5 commits into from

Conversation

gizemb
Copy link

@gizemb gizemb commented Jun 25, 2020

  • Introduces koin-test for mocking Repository instances in functional tests.

Our UI tests normally connect to live backend since they use the default implementation. That brings about some things to consider:

  • if we use one e-mail to complete the registration flow, then it'll be really registered, and we won't be able to run the same tests with the same e-mail for the 2nd time, backend will complain that the it is already registered.
  • with a live backend, we would be testing the backend itself too. so, if there are any problems w/ the backend, our tests would fail too, which creates a false-negative outcome. this might not be what we want.
  • on the other hand, a live backend frees us from the burden of mocking network requests and imitating the real behaviour from screen to screen.

In this PR, I made a very primitive mocking mechanism with koin-test. It uses Mockito to mock Repository instances. There is a limitation here: we hit the "Mockito cannot mock final classes" problem again with Mockito & Kotlin. However, for androidTests, MockMaker fix does not work, so we need to mock the Repository interface altogether, instead of concrete final RemoteDataSource class (which is our main problem). A solution to this problem would be to hide the RemoteDataSource behind an interface as well, but that sort of creates an unnecessary layer in production code.

@@ -14,8 +15,8 @@ class CreatePersonalAccountViewPagerAdapter(
override fun getCount(): Int = titles.size

override fun getItem(position: Int): Fragment =
//TODO add phone fragment
CreatePersonalAccountEmailFragment.newInstance()
if (position == PHONE_TAB_POSITION) CreatePersonalAccountPhoneFragment.newInstance()
Copy link
Author

Choose a reason for hiding this comment

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

espresso was complaining about ambiguous resources (since there were 2 instances of the same fragment). so I created this empty fragment, which will be filled soon :)

Choose a reason for hiding this comment

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

Please add the TODO() then :)

Copy link
Author

Choose a reason for hiding this comment

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

There's a TODO in xml layout

@@ -14,7 +14,7 @@
app:layout_constraintGuide_percent="0.228" />

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/createPersonalAccountTitleTextView"
android:id="@+id/createPersonalAccountHeaderTextView"
Copy link
Author

Choose a reason for hiding this comment

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

due to duplicate naming

@@ -17,6 +17,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/create_personal_account_with_email_edit_text_hint"
android:imeOptions="flagNoExtractUi"
Copy link
Author

Choose a reason for hiding this comment

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

for the weird keyboard behaviour in landscape mode.

Copy link

@android10 android10 left a comment

Choose a reason for hiding this comment

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

Good Job, although I will request changes to make sure that a discussion happens here.
We need to evaluate which is the best way to do end-to-end testing that involves networks requests.

This is one option (good job in any case) but also maybe for a more realistic scenario we use a mockServer?

I would also like to include contract testing at some point in time to make sure we are testing against the right contract of the api.

A bunch of resources that are worth reading:

@@ -14,8 +15,8 @@ class CreatePersonalAccountViewPagerAdapter(
override fun getCount(): Int = titles.size

override fun getItem(position: Int): Fragment =
//TODO add phone fragment
CreatePersonalAccountEmailFragment.newInstance()
if (position == PHONE_TAB_POSITION) CreatePersonalAccountPhoneFragment.newInstance()

Choose a reason for hiding this comment

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

Please add the TODO() then :)

@gizemb
Copy link
Author

gizemb commented Jun 30, 2020

Good Job, although I will request changes to make sure that a discussion happens here.
We need to evaluate which is the best way to do end-to-end testing that involves networks requests.

This is one option (good job in any case) but also maybe for a more realistic scenario we use a mockServer?

I would also like to include contract testing at some point in time to make sure we are testing against the right contract of the api.

A bunch of resources that are worth reading:

@android10 yes, I actually added this PR to start a discussion. This is not very ideal, but setting up a mock BE can consume time, and this does the job for now. I added an item in Collective. Will take a look at the readings by then, thanks :)

Base automatically changed from feature/registration_part_9 to master July 1, 2020 10:13
@gizemb
Copy link
Author

gizemb commented Jul 30, 2020

I'm closing this PR since it's a bit outdated and we need to re-investigate other options too

@gizemb gizemb closed this Jul 30, 2020
@gongracr gongracr deleted the feature/ui_test_mocks branch April 4, 2022 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants