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

41: Refactor assertSame() to be a top-level function #170

Merged
merged 13 commits into from
Oct 9, 2023
Merged
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@

### Library

#### Changed

- `ScreenshotRule.getScreenshotInstrumentationAnnotation()` is now a top-level function.
- `Collection<Annotation>.getAnnotation()` renamed to `Collection<Annotation>.findAnnotation()`.
- Package for `getScreenshotAnnotationName()` changed from `dev.testify.internal.extensions` to `dev.testify.annotation`.
- `ScreenshotRule.initializeView()` is now a top-level function.
- `EspressoHelper` now extends `ScreenshotLifecycle` and `beforeScreenshot()` has been replaced with `afterInitializeView()`

#### Added

- `isRunningOnUiThread()` added as a top-level function.
- `outputFileName()` added as an extension method for `Context`.
- Interface `AssertionState`
- Interface `ScreenshotLifecycleHost`
- `assertSame()` is now available as a top-level function, decoupled from `ScreenshotRule`

#### Removed

- `open fun ScreenshotRule.generateHighContrastDiff(baselineBitmap: Bitmap, currentBitmap: Bitmap)` has been removed. Use `class HighContrastDiff` directly.
- `ScreenshotRule.applyViewModifications()` has been removed. Use `TestifyConfiguration.applyViewModificationsMainThread()` instead.

#### Fixed

- [#175](https://github.com/ndtp/android-testify/issues/175): Output from Gradle Managed Devices now named according to Testify naming strategy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ open class ComposableScreenshotRule(
activity.disposeComposition()
}

@Deprecated(
message = "Please use configure()",
replaceWith = ReplaceWith("configure { [email protected] = captureMethod }")
)
override fun setCaptureMethod(captureMethod: CaptureMethod?): ComposableScreenshotRule {
this.captureMethod = configuration.captureMethod ?: ::pixelCopyCapture
return this
}

/**
* Set a screenshot view provider to capture only the @Composable bounds
*/
Expand Down Expand Up @@ -132,6 +141,7 @@ open class ComposableScreenshotRule(
*/
override fun afterInitializeView(activity: Activity) {
composeActions?.invoke(composeTestRule)
composeTestRule.waitForIdle()
super.afterInitializeView(activity)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ class AssertExpectedDeviceTest {
@ScreenshotInstrumentation
@Test
fun testMissingBaselineRecordMode() {
rule.setRecordModeEnabled(true)
rule
.configure {
isRecordMode = true
}
.assertSame()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,25 @@ package dev.testify

import android.app.Activity
import android.graphics.Bitmap
import android.view.ViewGroup
import dev.testify.annotation.ScreenshotInstrumentation
import dev.testify.internal.TestifyConfiguration
import io.mockk.every
import io.mockk.spyk
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Rule
import org.junit.Test

class ScreenshotRuleLifecycleTest {

inner class TestScreenshotRule : ScreenshotRule<TestActivity>(TestActivity::class.java) {
override fun applyViewModifications(parentView: ViewGroup) {
methodOrder.add("applyViewModifications")
}
private val configuration = spyk(TestifyConfiguration()) {
every { applyViewModificationsMainThread(any()) } answers { methodOrder.add("applyViewModifications") }
}

inner class TestScreenshotRule : ScreenshotRule<TestActivity>(
activityClass = TestActivity::class.java,
configuration = configuration
) {

override fun beforeActivityLaunched() {
methodOrder.add("beforeActivityLaunched")
Expand Down Expand Up @@ -79,18 +85,14 @@ class ScreenshotRuleLifecycleTest {
@Test
fun default() {
rule.assertSame()
assertEquals(
listOf(
"beforeAssertSame",
"beforeActivityLaunched",
"afterActivityLaunched",
"beforeInitializeView",
"applyViewModifications",
"afterInitializeView",
"beforeScreenshot",
"afterScreenshot"
),
methodOrder
)

assertEquals("beforeAssertSame", methodOrder[0])
assertEquals("beforeActivityLaunched", methodOrder[1])
assertEquals("afterActivityLaunched", methodOrder[2])
assertEquals("beforeInitializeView", methodOrder[3])
assertEquals("applyViewModifications", methodOrder[4])
assertEquals("afterInitializeView", methodOrder[5])
assertEquals("beforeScreenshot", methodOrder[6])
assertEquals("afterScreenshot", methodOrder[7])
}
}
6 changes: 6 additions & 0 deletions Library/src/main/java/dev/testify/CompatibilityMethods.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,10 @@ interface CompatibilityMethods<TRule : ScreenshotRule<TActivity>, TActivity : Ac
replaceWith = ReplaceWith("configure { [email protected] = compareMethod }")
)
fun setCompareMethod(compareMethod: CompareMethod?): TRule

@Deprecated(
message = "Please use configure()",
replaceWith = ReplaceWith("configure { [email protected] = isRecordMode }")
)
fun setRecordModeEnabled(isRecordMode: Boolean): TRule
}
28 changes: 28 additions & 0 deletions Library/src/main/java/dev/testify/ExtrasProvider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023 ndtp
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package dev.testify

import android.os.Bundle

typealias ExtrasProvider = (bundle: Bundle) -> Unit
Loading
Loading