No issue: remove unnecessary robolectric annotations.

Theoretically, this should marginally decrease the duration of our unit
test suite. In my testing, for 1 iteration each (i.e. noise is very
possible), the duration changed from 9m 32s to 8m 21s – a 71s
improvement.

---

To identify tests that were running with robolectric that didn't need to
be, I removed the @RunWith(FenixRobo... from all relevant files:
    sed -i '' "/@RunWith(FenixRobolectric/d" app/src/test/**/*.kt

I ran the tests and discovered which ones failed from the Classes tab of
the index.html test result file. Something like:
    tests = document.querySelectorAll('table')[3].querySelectorAll('tr');
    failureElements = tests.querySelectorAll('.failures');
    // TODO: extract the test names

Then I copied these results to a text file and compared them to all the
files that had robolectric test runners to figure out which ones still
pass:
    comm -1 -2 failures.txt changed_files.txt > robolectric_not_needed.txt

And undid the changes to the failing files:
    for i in $(cat robolectric_not_needed.txt); do git checkout $i; done

Then I removed the import statements on those files:
    for i in $(cut changed_files.txt); do sed -i '' "/import.*RunWith/d" $i; done
    for i in $(cat changed_files.txt); do sed -i '' "/import.*RobolectricTestRunner/d" $i; done
upstream-sync
Michael Comella 3 years ago committed by mergify[bot]
parent 474e9b035f
commit cc380695b8

@ -13,11 +13,8 @@ import io.mockk.verify
import mozilla.components.feature.addons.Addon
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@RunWith(FenixRobolectricTestRunner::class)
class AddonsManagementFragmentTest {
private lateinit var context: Context

@ -12,10 +12,7 @@ import io.mockk.verify
import mozilla.components.browser.toolbar.BrowserToolbar
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@RunWith(FenixRobolectricTestRunner::class)
class DynamicInfoBannerBehaviorTest {
@Test
fun `layoutDependsOn should not do anything if not for BrowserToolbar as a dependency`() {

@ -10,14 +10,11 @@ import mozilla.components.browser.state.search.SearchEngine
import mozilla.components.browser.state.store.BrowserStore
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
/**
* Just the Roboelectric tests for MetricsUtil. Splitting these files out means our other tests will run more quickly.
* FenixRobolectricTestRunner also breaks our ability to use mockkStatic on Base64.
*/
@RunWith(FenixRobolectricTestRunner::class)
class MetricsUtilsTestRoboelectric {
@Test

@ -12,12 +12,9 @@ import mozilla.components.browser.state.state.createTab
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.support.ktx.kotlin.getOrigin
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.components.Components
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.settings.sitepermissions.tryReloadTabBy
@RunWith(FenixRobolectricTestRunner::class)
class ExtensionsTest {
@Test

@ -7,12 +7,9 @@ package org.mozilla.fenix.ext
import mozilla.components.browser.state.state.content.DownloadState
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.library.downloads.DownloadItem
import java.io.File
@RunWith(FenixRobolectricTestRunner::class)
class ListTest {
@Test

@ -14,13 +14,10 @@ import mozilla.components.browser.menu.view.MenuButton
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.utils.Settings
@ExperimentalCoroutinesApi
@RunWith(FenixRobolectricTestRunner::class)
class HomeFragmentTest {
private lateinit var settings: Settings

@ -16,12 +16,9 @@ import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@ExperimentalCoroutinesApi
@RunWith(FenixRobolectricTestRunner::class)
class DownloadControllerTest {
private val downloadItem = DownloadItem(
id = "0",

@ -14,10 +14,7 @@ import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@RunWith(FenixRobolectricTestRunner::class)
class BiometricManagerKtTest {
lateinit var manager: BiometricManager

@ -8,10 +8,7 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@RunWith(FenixRobolectricTestRunner::class)
class StringTest {
@Test

@ -23,16 +23,13 @@ import org.junit.Before
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.components.PermissionStorage
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.utils.Settings
@OptIn(ExperimentalCoroutinesApi::class)
@RunWith(FenixRobolectricTestRunner::class)
class DeleteAndQuitTest {
val testDispatcher = TestCoroutineDispatcher()

@ -8,11 +8,8 @@ import mozilla.components.support.test.mock
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.settings.PhoneFeature
@RunWith(FenixRobolectricTestRunner::class)
class QuickSettingsFragmentReducerTest {
@Test

@ -11,15 +11,12 @@ import mozilla.components.feature.sitepermissions.SitePermissionsRules.Action.AL
import mozilla.components.feature.sitepermissions.SitePermissionsRules.Action.BLOCKED
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.settings.PhoneFeature.AUTOPLAY_AUDIBLE
import org.mozilla.fenix.settings.PhoneFeature.AUTOPLAY_INAUDIBLE
import org.mozilla.fenix.utils.Settings
import org.mozilla.fenix.wifi.SitePermissionsWifiIntegration
import org.mozilla.fenix.wifi.WifiConnectionMonitor
@RunWith(FenixRobolectricTestRunner::class)
class SitePermissionsWifiIntegrationTest {
lateinit var settings: Settings
lateinit var wifiIntegration: SitePermissionsWifiIntegration

@ -29,15 +29,12 @@ import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.browsingmode.BrowsingModeManager
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.home.HomeFragment
@RunWith(FenixRobolectricTestRunner::class)
class DefaultTabsTrayControllerTest {
@MockK(relaxed = true)
private lateinit var trayStore: TabsTrayStore

@ -9,16 +9,13 @@ import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.browser.browsingmode.BrowsingModeManager
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.tabstray.TrayPagerAdapter.Companion.POSITION_NORMAL_TABS
import org.mozilla.fenix.tabstray.TrayPagerAdapter.Companion.POSITION_PRIVATE_TABS
import org.mozilla.fenix.tabstray.TrayPagerAdapter.Companion.POSITION_SYNCED_TABS
@RunWith(FenixRobolectricTestRunner::class)
class TabLayoutMediatorTest {
private val modeManager: BrowsingModeManager = mockk(relaxed = true)
private val tabsTrayStore: TabsTrayStore = mockk(relaxed = true)

Loading…
Cancel
Save