1
0
Fork 0

For #9605: remove unnecessary @RunWith(AndroidJUnit4) in unit tests.

In unit tests, this annotation annotations defer to robolectric, non-trivially
increasing test runtime so it's important to remove them when they're
unnecessary.
master
Michael Comella 2020-04-01 12:52:32 -07:00 committed by Michael Comella
parent cb009f915c
commit f2acef66b5
5 changed files with 0 additions and 39 deletions

View File

@ -6,21 +6,15 @@ package org.mozilla.fenix.components.metrics
import androidx.navigation.NavController import androidx.navigation.NavController
import androidx.navigation.NavDestination import androidx.navigation.NavDestination
import androidx.test.ext.junit.runners.AndroidJUnit4
import mozilla.components.lib.crash.Crash import mozilla.components.lib.crash.Crash
import mozilla.components.lib.crash.CrashReporter import mozilla.components.lib.crash.CrashReporter
import mozilla.components.lib.crash.service.CrashReporterService import mozilla.components.lib.crash.service.CrashReporterService
import mozilla.components.support.test.any import mozilla.components.support.test.any
import mozilla.components.support.test.mock import mozilla.components.support.test.mock
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.spy import org.mockito.Mockito.spy
import org.mockito.Mockito.verify import org.mockito.Mockito.verify
import org.mozilla.fenix.TestApplication
import org.robolectric.annotation.Config
@RunWith(AndroidJUnit4::class)
@Config(application = TestApplication::class)
internal class BreadcrumbRecorderTest { internal class BreadcrumbRecorderTest {
@Test @Test
fun `ensure crash reporter recordCrashBreadcrumb is called`() { fun `ensure crash reporter recordCrashBreadcrumb is called`() {

View File

@ -8,39 +8,28 @@ import android.content.Context
import androidx.lifecycle.LifecycleCoroutineScope import androidx.lifecycle.LifecycleCoroutineScope
import androidx.navigation.NavController import androidx.navigation.NavController
import androidx.navigation.NavDirections import androidx.navigation.NavDirections
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.mockk.Runs import io.mockk.Runs
import io.mockk.every import io.mockk.every
import io.mockk.just import io.mockk.just
import io.mockk.mockk import io.mockk.mockk
import io.mockk.mockkObject
import io.mockk.verify import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runBlockingTest import kotlinx.coroutines.test.runBlockingTest
import mozilla.components.browser.search.SearchEngine import mozilla.components.browser.search.SearchEngine
import mozilla.components.browser.search.SearchEngineManager import mozilla.components.browser.search.SearchEngineManager
import mozilla.components.browser.session.Session import mozilla.components.browser.session.Session
import mozilla.components.support.test.robolectric.testContext
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.FenixApplication import org.mozilla.fenix.FenixApplication
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.TestApplication
import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.searchengine.CustomSearchEngineStore.PREF_FILE_SEARCH_ENGINES import org.mozilla.fenix.components.searchengine.CustomSearchEngineStore.PREF_FILE_SEARCH_ENGINES
import org.mozilla.fenix.ext.metrics import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.navigateSafe import org.mozilla.fenix.ext.navigateSafe
import org.mozilla.fenix.ext.searchEngineManager import org.mozilla.fenix.ext.searchEngineManager
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.utils.Settings
import org.mozilla.fenix.whatsnew.clear
import org.robolectric.annotation.Config
@ExperimentalCoroutinesApi @ExperimentalCoroutinesApi
@RunWith(AndroidJUnit4::class)
@Config(application = TestApplication::class)
class SearchInteractorTest { class SearchInteractorTest {
private val lifecycleScope: LifecycleCoroutineScope = mockk(relaxed = true) private val lifecycleScope: LifecycleCoroutineScope = mockk(relaxed = true)
@ -121,10 +110,6 @@ class SearchInteractorTest {
fun onTextChanged() { fun onTextChanged() {
val store: SearchFragmentStore = mockk(relaxed = true) val store: SearchFragmentStore = mockk(relaxed = true)
val context: HomeActivity = mockk(relaxed = true) val context: HomeActivity = mockk(relaxed = true)
val settings = testContext.settings().apply { testContext.settings().clear() }
mockkObject(Settings)
every { Settings.getInstance(context = context) } returns settings
every { store.state } returns mockk(relaxed = true) every { store.state } returns mockk(relaxed = true)

View File

@ -5,7 +5,6 @@
package org.mozilla.fenix.settings.deletebrowsingdata package org.mozilla.fenix.settings.deletebrowsingdata
import android.content.Context import android.content.Context
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.mockk.Runs import io.mockk.Runs
import io.mockk.every import io.mockk.every
import io.mockk.just import io.mockk.just
@ -21,14 +20,9 @@ import mozilla.components.concept.engine.Engine
import org.junit.After import org.junit.After
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.TestApplication
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
import org.robolectric.annotation.Config
@ExperimentalCoroutinesApi @ExperimentalCoroutinesApi
@RunWith(AndroidJUnit4::class)
@Config(application = TestApplication::class)
class DefaultDeleteBrowsingDataControllerTest { class DefaultDeleteBrowsingDataControllerTest {
private val mainThreadSurrogate = newSingleThreadContext("UI thread") private val mainThreadSurrogate = newSingleThreadContext("UI thread")

View File

@ -6,21 +6,15 @@ package org.mozilla.fenix.utils
import androidx.core.view.OneShotPreDrawListener import androidx.core.view.OneShotPreDrawListener
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.mockk.mockk import io.mockk.mockk
import io.mockk.verify import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.test.runBlockingTest import kotlinx.coroutines.test.runBlockingTest
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.TestApplication
import org.robolectric.annotation.Config
@ObsoleteCoroutinesApi @ObsoleteCoroutinesApi
@ExperimentalCoroutinesApi @ExperimentalCoroutinesApi
@RunWith(AndroidJUnit4::class)
@Config(application = TestApplication::class)
class FragmentPreDrawManagerTest { class FragmentPreDrawManagerTest {
private fun doNothing() { /*noop*/ } private fun doNothing() { /*noop*/ }

View File

@ -4,15 +4,9 @@ package org.mozilla.fenix.whatsnew
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.TestApplication
import org.robolectric.annotation.Config
@RunWith(AndroidJUnit4::class)
@Config(application = TestApplication::class)
class WhatsNewVersionTest { class WhatsNewVersionTest {
@Test @Test
fun testMajorVersionNumber() { fun testMajorVersionNumber() {