Merge "Make golden path relative to $ANDROID_BUILD_TOP" into tm-qpr-dev

This commit is contained in:
Jay Aliomer
2022-11-29 23:04:41 +00:00
committed by Android (Google) Code Review
4 changed files with 24 additions and 8 deletions

View File

@@ -38,12 +38,18 @@ import platform.test.screenshot.ScreenshotTestRule
import platform.test.screenshot.getEmulatedDevicePathConfig
/** A rule for Compose screenshot diff tests. */
class ComposeScreenshotTestRule(emulationSpec: DeviceEmulationSpec) : TestRule {
class ComposeScreenshotTestRule(
emulationSpec: DeviceEmulationSpec,
assetPathRelativeToBuildRoot: String
) : TestRule {
private val colorsRule = MaterialYouColorsRule()
private val deviceEmulationRule = DeviceEmulationRule(emulationSpec)
private val screenshotRule =
ScreenshotTestRule(
SystemUIGoldenImagePathManager(getEmulatedDevicePathConfig(emulationSpec))
SystemUIGoldenImagePathManager(
getEmulatedDevicePathConfig(emulationSpec),
assetPathRelativeToBuildRoot
)
)
private val composeRule = createAndroidComposeRule<ScreenshotActivity>()
private val delegateRule =

View File

@@ -34,13 +34,19 @@ import platform.test.screenshot.*
/**
* A rule that allows to run a screenshot diff test on a view that is hosted in another activity.
*/
class ExternalViewScreenshotTestRule(emulationSpec: DeviceEmulationSpec) : TestRule {
class ExternalViewScreenshotTestRule(
emulationSpec: DeviceEmulationSpec,
assetPathRelativeToBuildRoot: String
) : TestRule {
private val colorsRule = MaterialYouColorsRule()
private val deviceEmulationRule = DeviceEmulationRule(emulationSpec)
private val screenshotRule =
ScreenshotTestRule(
SystemUIGoldenImagePathManager(getEmulatedDevicePathConfig(emulationSpec))
SystemUIGoldenImagePathManager(
getEmulatedDevicePathConfig(emulationSpec),
assetPathRelativeToBuildRoot
)
)
private val delegateRule =
RuleChain.outerRule(colorsRule).around(deviceEmulationRule).around(screenshotRule)

View File

@@ -23,11 +23,11 @@ import platform.test.screenshot.PathConfig
/** A [GoldenImagePathManager] that should be used for all SystemUI screenshot tests. */
class SystemUIGoldenImagePathManager(
pathConfig: PathConfig,
override val assetsPathRelativeToRepo: String = "tests/screenshot/assets"
assetsPathRelativeToBuildRoot: String
) :
GoldenImagePathManager(
appContext = InstrumentationRegistry.getInstrumentation().context,
assetsPathRelativeToRepo = assetsPathRelativeToRepo,
assetsPathRelativeToBuildRoot = assetsPathRelativeToBuildRoot,
deviceLocalPath =
InstrumentationRegistry.getInstrumentation()
.targetContext

View File

@@ -41,13 +41,17 @@ import platform.test.screenshot.matchers.BitmapMatcher
/** A rule for View screenshot diff unit tests. */
class ViewScreenshotTestRule(
emulationSpec: DeviceEmulationSpec,
private val matcher: BitmapMatcher = UnitTestBitmapMatcher
private val matcher: BitmapMatcher = UnitTestBitmapMatcher,
assetsPathRelativeToBuildRoot: String
) : TestRule {
private val colorsRule = MaterialYouColorsRule()
private val deviceEmulationRule = DeviceEmulationRule(emulationSpec)
private val screenshotRule =
ScreenshotTestRule(
SystemUIGoldenImagePathManager(getEmulatedDevicePathConfig(emulationSpec))
SystemUIGoldenImagePathManager(
getEmulatedDevicePathConfig(emulationSpec),
assetsPathRelativeToBuildRoot
)
)
private val activityRule = ActivityScenarioRule(ScreenshotActivity::class.java)
private val delegateRule =