Closed Bug 2030917 Opened 3 months ago Closed 2 months ago

Use assertIs<Type>() instead of assertTrue(x is Type) in tests

Categories

(Firefox for Android :: Tooling, enhancement)

All
Android
enhancement

Tracking

()

RESOLVED FIXED
152 Branch
Tracking Status
firefox152 --- fixed

People

(Reporter: mkozinski, Assigned: mkozinski)

References

(Blocks 1 open bug)

Details

(Whiteboard: [fxdroid][group2][quickwins])

Attachments

(8 files)

assertIs<SomeType>(x) from kotlin.test gives a smart cast on the variable and a descriptive error on failure. Add a lint check with a quick-fix that will guide developers towards this nicer API, by showing a warning in the IDE complete with a "quick-fix" to replace code with one click. Also replace all existing usages of assertTrue(x is Type) in fenix and android-components tests.

Pushed by mkozinski@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/2d9ae4b9de28 https://hg.mozilla.org/integration/autoland/rev/ecda386de4e1 Use assertIs<Type>() instead of assertTrue(x is Type) in Fenix tests r=android-reviewers,nalexander,twhite,sfamisa https://github.com/mozilla-firefox/firefox/commit/e46c56185971 https://hg.mozilla.org/integration/autoland/rev/8e888baf2818 Use assertIs<Type>() instead of assertTrue(x is Type) in android-components r=android-reviewers,nalexander,sfamisa https://github.com/mozilla-firefox/firefox/commit/87d935f6121d https://hg.mozilla.org/integration/autoland/rev/7f08d037b646 Use assertIs<Type>() instead of assertTrue(x is Type) in Focus tests r=android-reviewers,mcarare https://github.com/mozilla-firefox/firefox/commit/65a0823890d8 https://hg.mozilla.org/integration/autoland/rev/21a94c445834 Use assertIs<Type>() instead of assertTrue(x is Type) in GeckoView tests r=geckoview-reviewers,ohall https://github.com/mozilla-firefox/firefox/commit/f55dad5b2c83 https://hg.mozilla.org/integration/autoland/rev/99d780f7488e Add an Android Lint check for assertTrue(x is Type) and a quick-fix to replace with assertIs<Type>() r=android-reviewers,nalexander,pollymce

AssertIsDetector was always meant to only be a warning with a quick-fix, so it helps developers find their way to the recommended API without annoying them with backouts. The original patch missed the additional configuration applied in android-components that upgrades all warnings to errors.

A patch has been attached on this bug, which was already closed. Filing a separate bug will ensure better tracking. If this was not by mistake and further action is needed, please alert the appropriate party. (Or: if the patch doesn't change behavior -- e.g. landing a test case, or fixing a typo -- then feel free to disregard this message)

Pushed by mkozinski@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/95f062277259 https://hg.mozilla.org/integration/autoland/rev/b6996a111698 Downgrade AssertIsDetector to warning in android-components r=android-reviewers,gmalekpour,twhite https://github.com/mozilla-firefox/firefox/commit/b4956d72d510 https://hg.mozilla.org/integration/autoland/rev/e995ff3b4a13 Allow lint to import assertIs when applying the quick-fix r=android-reviewers,twhite https://github.com/mozilla-firefox/firefox/commit/19105e0bd868 https://hg.mozilla.org/integration/autoland/rev/5a1ee61980ce Simplify redundant skipParenthesizedExprDown in AssertIsDetector r=android-reviewers,gmalekpour
See Also: → 2049304
See Also: → 2050306
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: