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 for running tests #65

Merged
merged 20 commits into from
Aug 19, 2024
Merged

Conversation

AsimRibo
Copy link
Contributor

πŸ“· Screenshots

πŸ“„ Context

Tests can finally be run. Some of them are failing but that is a problem for another day.

πŸ“ Changes

πŸ“Ž Related PR

🚫 Breaking

πŸ› οΈ How to test

⏱️ Next steps

Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@AsimRibo
Copy link
Contributor Author

AsimRibo commented Aug 5, 2024

Tests can be run now and all are passing, some work still needs to be done in SentinelFragmentTests.

@AsimRibo AsimRibo changed the base branch from update-dependencies-04-2024 to develop August 5, 2024 21:31
Copy link
Collaborator

@KCeh KCeh left a comment

Choose a reason for hiding this comment

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

Nice progress, I will do more detailed review once this PR is out of draft.
But once again kudos πŸš€

Comment on lines 15 to 26

<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
android:exported="false"
tools:node="merge">

<meta-data
android:name="androidx.work.WorkManagerInitializer"
android:value="androidx.startup"
tools:node="remove" />
</provider>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this needed?
We removed need for this in last release

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 can't remember if there were any conflicts, but it is possible it is from that. I will re-check 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.

Okay, I see now. This is from initial commit to this branch by Neven when we were figuring out what is wrong with the tests. I will check if this can be removed.

Comment on lines 37 to 40
WorkManager.initialize(
context,
Configuration.Builder().build()
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here

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 is only for Tests. WorkManager is missing and SentinelTests couldn't be run.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By removing meta-data for WorkManager this can also be removed.

Comment on lines 21 to 22
Manifest.permission.POST_NOTIFICATIONS to false,
Manifest.permission.POST_NOTIFICATIONS to false,
Copy link
Collaborator

Choose a reason for hiding this comment

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

POST_NOTIFICATIONS twice

Copy link
Collaborator

Choose a reason for hiding this comment

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

Still twice...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed, finally πŸ˜„

@AsimRibo
Copy link
Contributor Author

Fixed SentinelFragmentTests as well. I'd say it is fine for now but we should expand them in future to cover all cases and re-arrange test code to make it easier to read(maybe add AAA comments).

@AsimRibo AsimRibo marked this pull request as ready for review August 11, 2024 13:15
@AsimRibo AsimRibo requested a review from KCeh August 11, 2024 13:15
Comment on lines +124 to +150
private fun checkDeviceSpecificFields(html: String): String {
val fields = listOf(
"screen_width",
"screen_height",
"screen_size",
"screen_density",
"font_scale"
)

val fieldPatterns = fields.map { field ->
field to Regex("""<div>$field:\s*[^<]*</div>""")
}

var updatedHtml = html

fieldPatterns.forEach { (field, pattern) ->
val matchResult = pattern.find(updatedHtml)
if (matchResult == null) {
throw AssertionError("Field $field is missing in the device object")
} else {
updatedHtml = updatedHtml.replace(matchResult.value, """<div>$field: </div>""")
}
}

return updatedHtml
}

Copy link
Contributor Author

@AsimRibo AsimRibo Aug 11, 2024

Choose a reason for hiding this comment

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

When it comes to StringBuilder tests I didn't find an elegant way to mock these fields like it is the case with ReflectionHelpers. So I went with this approach because I think it is only important to assert that field is there.

When I get more familiar with Roboelectric, I will return to this, unless you have suggestions.

Copy link
Collaborator

@KCeh KCeh left a comment

Choose a reason for hiding this comment

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

Kudos for taking the initiative and finally patching up tests πŸš€

I also don't have too much exp with πŸ€– Robolectric and I see we quite often have patterns like checkDeviceSpecificFields in tests. I assume we could probably improve that. But first and foremost everything is running as expected!

P.S.
Maybe you could share you gained knowledge on internal edu or team events πŸ€”

P.S. Part II
Take a look at Notification permission comment

Comment on lines 21 to 22
Manifest.permission.POST_NOTIFICATIONS to false,
Manifest.permission.POST_NOTIFICATIONS to false,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Still twice...

@@ -10,7 +10,7 @@
<application>

<activity
android:name=".ui.main.SentinelActivity"
android:name="com.infinum.sentinel.ui.main.SentinelActivity"
Copy link
Collaborator

Choose a reason for hiding this comment

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

πŸ‘

Copy link

@AsimRibo AsimRibo merged commit ac62958 into develop Aug 19, 2024
6 checks passed
@KCeh KCeh deleted the fix-tests-dependencies-04-package-name branch August 20, 2024 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants