-
Notifications
You must be signed in to change notification settings - Fork 551
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
Topic Info Tablet Robolectric Tests [DON'T MERGE] #1480
Conversation
TopicInfoFragment.newInstance(internalProfileId = 0, topicId = RATIOS_TOPIC_ID) | ||
activity.supportFragmentManager.beginTransaction() | ||
.add(R.id.topic_info_container, topicInfoFragment, TopicInfoFragment.TOPIC_INFO_FRAGMENT_TAG) | ||
.commit() |
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.
You should use commitNow
to ensure there's no delay in the UI showing up.
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.
Done
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.
@MohamedMedhat1998 can you include a video of the observed behavior to provide context on the issue you're observing? Also, what have you tried to do to fix this, & what are your thoughts on what's going wrong?
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 possible that the initial set up has something to do with it being created in an expanded state?
android:id="@+id/topic_info_container" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".testing.TopicInfoTestActivity" /> |
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.
Add a new line at EOF
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.
Done
@BenHenning for some reason this PR is allowed to merge even without a review. Any idea why? Edit: Nevermind, I just noticed this isn't being merged to develop! |
|
||
fun handleOnCreate() { | ||
activity.setContentView(R.layout.topic_info_test_activity) | ||
val topicInfoFragment = |
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.
How about putting a check here if a fragment already exist or not? WDYT
if (getTopicInfoFragment() == null)
|
||
private fun getTopicDescriptionTextView(activity: TopicInfoTestActivity): TextView? { | ||
val topicInfoFragment = | ||
activity.supportFragmentManager.findFragmentByTag(TopicInfoFragment.TOPIC_INFO_FRAGMENT_TAG) |
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.
How about if we use the placeholder_id
rather than TAG
? This will remove using extra TAG part.
Intents.release() | ||
} | ||
|
||
private fun getTopicDescriptionTextView(activity: TopicInfoTestActivity): TextView? { |
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.
How about if we move these helper methods at the bottom of the file and bringing test cases at the top after @After
method? This will make it looks good and if in future some more test cases a consistency will be there that all helper methods are at bottom and test cases in between.
@Test | ||
fun test() { | ||
launch(TopicInfoTestActivity::class.java).use { | ||
it.onActivity { activity -> |
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.
How about if we use scenario ->
rather than using it
?
} | ||
|
||
@Test | ||
fun test() { |
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 agree with the Ben comment if you could add some more about the current problem you are seeing for this.
Name of the test case can be more understandable just to understand what the test is all about.
@BenHenning
So, the test case is failing.
I haven't tried fixing that but I think the initial state of the fragment is set up incorrectly.
That is what I'm thinking too. |
Thanks @MohamedMedhat1998. This seems like the same issue as #1379 to me. The problem is likely that the topic page is in an initial loading state before becoming fully loaded. If this were Robolectric-specific, using TestCoroutineDispatchers would almost certainly fix the issue. Unfortunately, I haven't had time to figure out how to adapt these to an IdlingResource yet (it's not straightforward because Espresso isn't running with a fake clock, and it's not clear to me if it's valid to run background coroutines on a different clock than the wall clock being used by the main thread). You could try to integrate TestCoroutineDispatchers and make this test first pass with Robolectric, then create a custom IdlingResource to see if it'll work on Espresso. I'm not sure exactly what the custom idling resource will look like yet. |
@BenHenning @rt4914 I have tried using
Error:
|
…olectric-tests # Conflicts (Resolved): # app/src/main/java/org/oppia/app/activity/ActivityComponent.kt -Added some test case
@MohamedMedhat1998 when you used TestCoroutineDispatchers did you run the test with Robolectric? Given that this is an app module test, I'm not actually expecting it to work without #59 being resolved since we can't properly sync the two different application components being created in app module tests. |
@BenHenning yes, I was running it with robolectric. |
@MohamedMedhat1998 in that case I suggest migrating the test suite or moving the tests in question to a local test suite like StateFragmentLocalTest & following the same Dagger setup we have there (where we're actually specifying the application class to use via a References
|
I think the main problem we are facing now is the |
@MohamedMedhat1998 Either update/finish this PR or if this is not needed then close this PR. |
closing this PR because it was created to demonstrate the issue with robolectric tests and |
Notes
The current test-case fails because of some flickering effect that I noticed when I ran the app on my real device.
Here is the code
Which means that the text start in expanded state instead of collapsed state.
When I inverted the order of the assertions, the test passed.
So, is this a problem in the code itself?
If so, should I continue writing these tests tell the problem gets resolved, or there is something else that I can do?
Explanation
Checklist