Optimize WarmUpRule #1310

This PR is made of 2 commits.
The first is just a mass rename in order to spare 1 line of code every time `WarmUpRule` is used.
The second tweaks `WarmUpRule` so that the warmup code is only run once per test class.
This commit is contained in:
Marco Romano
2023-09-13 16:27:32 +02:00
committed by GitHub
54 changed files with 69 additions and 117 deletions

View File

@@ -37,8 +37,7 @@ import org.junit.Rule
import org.junit.Test
class RootPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -37,8 +37,7 @@ import org.junit.Test
class LoggedInPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -31,8 +31,7 @@ import org.junit.Test
class AnalyticsOptInPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -30,8 +30,7 @@ import org.junit.Test
class AnalyticsPreferencesPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -32,8 +32,7 @@ import org.junit.Test
class AddPeoplePresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private lateinit var presenter: AddPeoplePresenter

View File

@@ -60,8 +60,7 @@ private const val AN_URI_FROM_GALLERY = "content://uri_from_gallery"
@RunWith(RobolectricTestRunner::class)
class ConfigureRoomPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private lateinit var presenter: ConfigureRoomPresenter

View File

@@ -44,8 +44,7 @@ import org.junit.Test
class CreateRoomRootPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private lateinit var userRepository: FakeUserRepository

View File

@@ -33,8 +33,7 @@ import org.junit.Test
class DefaultUserListPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private val userRepository = FakeUserRepository()

View File

@@ -32,8 +32,7 @@ import org.junit.Test
class MigrationScreenPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -39,8 +39,7 @@ import org.junit.Test
class NotificationsOptInPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private var isFinished = false

View File

@@ -50,8 +50,7 @@ import org.junit.Rule
import org.junit.Test
class InviteListPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -39,8 +39,7 @@ import org.junit.Test
class LeaveRoomPresenterImplTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -42,8 +42,7 @@ import org.junit.Test
class SendLocationPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private val permissionsPresenterFake = PermissionsPresenterFake()

View File

@@ -35,8 +35,7 @@ import org.junit.Test
class ShowLocationPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private val permissionsPresenterFake = PermissionsPresenterFake()

View File

@@ -33,8 +33,7 @@ import org.junit.Test
class ChangeServerPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -35,8 +35,7 @@ import org.junit.Test
class OidcPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -31,8 +31,7 @@ import org.junit.Test
class ChangeAccountProviderPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -39,8 +39,7 @@ import org.junit.Test
class ConfirmAccountProviderPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -38,8 +38,7 @@ import org.junit.Test
class LoginPasswordPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -38,8 +38,7 @@ import org.junit.Test
class SearchAccountProviderPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -37,8 +37,7 @@ import org.junit.Test
class WaitListPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -32,8 +32,7 @@ import org.junit.Test
class LogoutPreferencePresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -86,8 +86,7 @@ import kotlin.time.Duration.Companion.milliseconds
class MessagesPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private val mockMediaUrl: Uri = mockk("localMediaUri")

View File

@@ -41,8 +41,7 @@ import org.junit.Test
class ActionListPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -43,8 +43,7 @@ import org.junit.Test
class AttachmentsPreviewPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private val mediaPreProcessor = FakeMediaPreProcessor()

View File

@@ -39,8 +39,7 @@ import org.junit.Test
class ForwardMessagesPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()

View File

@@ -44,8 +44,7 @@ private val TESTED_MEDIA_INFO = aFileInfo()
class MediaViewerPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()

View File

@@ -35,8 +35,7 @@ import org.junit.Test
class ReportMessagePresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -69,8 +69,7 @@ import java.io.File
class MessageComposerPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private val pickerProvider = FakePickerProvider().apply {

View File

@@ -51,8 +51,7 @@ import java.util.Date
class TimelinePresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -33,8 +33,7 @@ import org.junit.Test
class CustomReactionPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private val presenter = CustomReactionPresenter(emojibaseProvider = FakeEmojibaseProvider())

View File

@@ -37,8 +37,7 @@ import org.junit.Test
class ReactionSummaryPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private val aggregatedReaction = anAggregatedReaction(userId = A_USER_ID, key = "👍", isHighlighted = true)

View File

@@ -32,8 +32,7 @@ import org.junit.Test
class RetrySendMenuPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private val room = FakeMatrixRoom()

View File

@@ -29,8 +29,7 @@ import org.junit.Test
class OnBoardingPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -35,8 +35,7 @@ import org.junit.Test
class CreatePollPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private var navUpInvocationsCount = 0

View File

@@ -27,8 +27,7 @@ import org.junit.Test
class AboutPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -30,8 +30,7 @@ import org.junit.Test
class AnalyticsSettingsPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -35,8 +35,7 @@ import org.junit.Test
class DeveloperSettingsPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -30,8 +30,7 @@ import org.junit.Test
class ConfigureTracingPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test
fun `present - initial state`() = runTest {

View File

@@ -37,8 +37,7 @@ import org.junit.Test
class PreferencesRootPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -36,8 +36,7 @@ const val A_LONG_DESCRIPTION = "I have seen a bug!"
class BugReportPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -31,8 +31,7 @@ import org.junit.Test
class CrashDetectionPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -38,8 +38,7 @@ import org.junit.Test
class RageshakeDetectionPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
companion object {

View File

@@ -31,8 +31,7 @@ import org.junit.Test
class RageshakePreferencesPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -57,8 +57,7 @@ import kotlin.time.Duration.Companion.milliseconds
@ExperimentalCoroutinesApi
class RoomDetailsPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private fun aRoomDetailsPresenter(
room: MatrixRoom,

View File

@@ -48,8 +48,7 @@ import java.io.File
@ExperimentalCoroutinesApi
class RoomDetailsEditPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
private lateinit var fakePickerProvider: FakePickerProvider

View File

@@ -46,8 +46,7 @@ import org.junit.Test
internal class RoomInviteMembersPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -43,8 +43,7 @@ import org.junit.Test
@ExperimentalCoroutinesApi
class RoomMemberListPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -38,8 +38,7 @@ import org.junit.Test
@ExperimentalCoroutinesApi
class RoomMemberDetailsPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -61,8 +61,7 @@ import org.junit.Test
class RoomListPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -35,8 +35,7 @@ import org.junit.Test
@ExperimentalCoroutinesApi
class VerifySelfSessionPresenterTests {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -35,8 +35,7 @@ const val A_PERMISSION = "A_PERMISSION"
class DefaultPermissionsPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -27,8 +27,7 @@ import org.junit.Test
class NoopPermissionsPresenterTest {
@Rule
@JvmField
@get:Rule
val warmUpRule = WarmUpRule()
@Test

View File

@@ -32,17 +32,22 @@ import kotlin.time.Duration.Companion.seconds
* Applying this test rule ensures that the slow initialisation is not done
* inside runTest which has a short default timeout.
*/
class WarmUpRule: TestRule {
override fun apply(base: Statement, description: Description): Statement = object: Statement() {
override fun evaluate() {
runTest(timeout = 60.seconds) {
moleculeFlow(RecompositionMode.Immediate) {
// Do nothing
}.test {
awaitItem() // Await a Unit composition
}
}
base.evaluate()
class WarmUpRule : TestRule {
companion object {
init {
warmUpMolecule()
}
}
override fun apply(base: Statement, description: Description): Statement = base
}
private fun warmUpMolecule() {
runTest(timeout = 60.seconds) {
moleculeFlow(RecompositionMode.Immediate) {
// Do nothing
}.test {
awaitItem() // Await a Unit composition
}
}
}