-
Notifications
You must be signed in to change notification settings - Fork 731
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
Adding unit tests for live location sharing aggregation code (PSF-1063) #6267
Conversation
val event = Event(senderId = A_SENDER_ID) | ||
val beaconLocationData = MessageBeaconLocationDataContent() | ||
|
||
val resultNoRelatedEventId = liveLocationAggregationProcessor.handleBeaconLocationData( |
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.
as we're actioning different inputs no related event id
and empty related event id
, this feels like two separate tests (similar comment for the test below)
a parameterised test could potentially cover all these validation cases (orrrrr the naive parameterised tests I've started doing like this
for the parameters themselves, are null/empty ids possible? would be nice if we could catch them further up the chain and avoid invalid empty ids
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 your point. I created a loop on a list of ignored values to group the similar tests: see 912244a. I didn't use parametrized tests since I don't like the boilerplate syntax in Junit 4. I am wondering if it is possible to switch to Junit 5 in Android: the syntax for parametrized tests is much nicer.
For you last point, I agree but I didn't change anything since it would require to change the events aggregation process in a more general way.
aggregatedEntity.isActive shouldBeEqualTo true | ||
aggregatedEntity.endOfLiveTimestampMillis shouldBeEqualTo A_TIMESTAMP + A_TIMEOUT_MILLIS | ||
aggregatedEntity.lastLocationContent shouldBeEqualTo null | ||
previousEntities.forEach { entity -> |
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.
val previousEntities = mockPreviousLiveLocationShareAggregatedSummaryEntities()
previousEntities.forEach { entity ->
entity.isActive shouldBeEqualTo false
}
it looks like the previousEntities
aren't used?
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.
In fact, they are. They are modified internally by the aggregation process. And here we check the result is correct. I could not find a better way to ensure the aggregation is correct. I am open to any suggestion that could improve that.
savedLocationData?.getBestLocationInfo()?.geoUri shouldBeEqualTo A_GEO_URI | ||
} | ||
|
||
private fun mockLiveLocationShareAggregatedSummaryEntityForEvent( |
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 could be helpful to name these helpers with the data they're fetching
givenLastRoomBeaconQueryReturns(roomId, eventId, beaconLocation)
val activeSummary = LiveLocationShareAggregatedSummaryEntity(
eventId = "ignored-value",
roomId = A_ROOM_ID,
userId = A_SENDER_ID,
isActive = true
)
givenLocationSummaryQueryReturns(activeSummary)
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 clarified the namings here: ed13244
@@ -21,16 +21,59 @@ import io.mockk.mockk | |||
import io.realm.Realm | |||
import io.realm.RealmModel | |||
import io.realm.RealmQuery | |||
import io.realm.RealmResults | |||
import io.realm.kotlin.where | |||
|
|||
internal class FakeRealm { |
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.
💯 for updating the fake!
val instance = mockk<WorkManagerProvider>() | ||
|
||
init { | ||
val workManager = mockk<WorkManager>() |
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'm wondering if we should be explicitly expecting the tests to mock enqueueUniqueWork
cancelUniqueWork
rather than applying it by default, we can make the test cases more resilient by also verifying against the arguments
class FakeWorkManagerProvider(val fakeWorkManager = FakeWorkManager()) {
val instance = mockk<WorkManagerProvider>().also {
every { workManager } returns fakeWorkManager.instance
}
}
class FakeWorkManager {
val instance = mockk<WorkManager>()
fun expectCancelUniqueWork() {
every { instance.cancelUniqueWork(any()) } returns mockk()
}
fun verifyCancelUniqueWork(name: String) {
verify { instance.cancelUniqueWork(name) }
}
}
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 you are right. I will make an update.
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.
Updated here: 454209a
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.
💯 thanks for the updates!
912244a
to
00a5830
Compare
00a5830
to
12880e0
Compare
12880e0
to
ac4b336
Compare
SonarCloud Quality Gate failed. |
Type of change
Content
Adding unit tests to cover code of aggregation process of live location share events.
Motivation and context
Closes #6155
Screenshots / GIFs
Tests
Tested devices
Checklist