本文已参与「新人创造礼」活动,一起开启创造之路。

Paparazzi

一个Android包, 可以在没有物理设备或许模拟器的情况下, 烘托运用页面.

class LaunchViewTest {
  @get:Rule
  val paparazzi = Paparazzi(
    deviceConfig = PIXEL_5,
    theme = "android:Theme.Material.Light.NoActionBar"
    // ...see docs for more options
  )
  @Test
  fun launchView() {
    val view = paparazzi.inflate<LaunchView>(R.layout.launch)
    // or...
    // val view = LaunchView(paparazzi.context)
    view.setModel(LaunchModel(title = "paparazzi"))
    paparazzi.snapshot(view)
  }
  @Test
  fun launchComposable() {
    paparazzi.snapshot {
      MyComposable()
    }
  }
}

使命

$ ./gradlew sample:testDebug

运转测验并且在sample/build/reports/paparazzi/生成HTML陈述, 陈述会显现全部测验的运转的快照.

$ ./gradlew sample:recordPaparazziDebug

将快照保存为黄金值到预界说的受源代码管理的位置(默许保存到src/test/snapshots).

$ ./gradlew sample:verifyPaparazziDebug

运转测验并查验之前记录的黄金值. 失利的话会在sample/out/failures生成diff文件.

要想检查更多的信息, 请检查sample项目.

Git LFS

引荐运用Git LFS保存快照. 下面是快速设置:

$ brew install git-lfs
$ git config core.hooksPath  # optional, confirm where your git hooks will be installed
$ git lfs install --local
$ git lfs track "**/snapshots/**/*.png"
$ git add .gitattributes

在CI上, 可以像这样设置:

$HOOKS_DIR/pre-receive

# compares files that match .gitattributes filter to those actually tracked by git-lfs
diff <(git ls-files ':(attr:filter=lfs)' | sort) <(git lfs ls-files -n | sort) >/dev/null
ret=$?
if [[ $ret -ne 0 ]]; then
  echo >&2 "This remote has detected files committed without using Git LFS. Run 'brew install git-lfs && git lfs install' to install it and re-commit your files.";
  exit 1;
fi

your_build_script.sh

if [[ is running snapshot tests ]]; then
  # fail fast if files not checked in using git lfs
  "$HOOKS_DIR"/pre-receive
  git lfs install --local
  git lfs pull
fi

Jetifier

如果在运用Jetifier搬迁Support包, 将下面的内容添加到gradle.properties文件来扫除绑缚的Android依赖.

android.jetifier.ignorelist=android-base-common,common

Releases

改变日志保留了发版的前史.

运用插件:

buildscript {
  repositories {
    mavenCentral()
    google()
  }
  dependencies {
    classpath 'app.cash.paparazzi:paparazzi-gradle-plugin:1.0.0'
  }
}
apply plugin: 'app.cash.paparazzi'

运用插件DSL:

plugins {
  id 'app.cash.paparazzi' version '1.0.0'
}

开发版的快照在Sonatype的快照仓库.

 repositories {
   // ...
   maven {
     url 'https://oss.sonatype.org/content/repositories/snapshots/'
   }
 }

包名 app.cash.paparazzi

类型

名称 简介
DeviceConfig [jvm] 数据类DeviceConfig(val screenHeight:Int= 1280, val screenWidth:Int= 768, val xdpi:Int= 320, val ydpi:Int= 320, val orientation: ScreenOrientation = ScreenOrientation.PORTRAIT, val uiMode: UiMode = UiMode.NORMAL, val nightMode: NightMode = NightMode.NOTNIGHT, val density: Density = Density.XHIGH, val fontScale:Float= 1.0f, val layoutDirection: LayoutDirection = LayoutDirection.LTR, val locale:String? = null, val ratio: ScreenRatio = ScreenRatio.NOTLONG, val size: ScreenSize = ScreenSize.NORMAL, val keyboard: Keyboard = Keyboard.NOKEY, val touchScreen: TouchScreen = TouchScreen.FINGER, val keyboardState: KeyboardState = KeyboardState.SOFT, val softButtons:Boolean= true, val navigation: Navigation = Navigation.NONAV, val released:String= “November 13, 2012”) 为多样的设备供给了 FolderConfiguration 和 HardwareConfig. 也供给了通用函数来解析build.propattrs.xml以生成恰当的map.
Environment [jvm] 数据类Environment(val platformDir:String, val appTestDir:String, val resDir:String, val assetsDir:String, val packageName:String, val compileSdkVersion:Int, val resourcePackageNames:List<String>)
Flags [jvm] 对象Flags
HtmlReportWriter [jvm] 类HtmlReportWriter@JvmOverloadsconstructor(runName:String= defaultRunName(), rootDirectory:File= File(“build/reports/paparazzi”), snapshotRootDirectory:File= File(“src/test/snapshots”)) :SnapshotHandler 创建了HTML陈述, 防止向现已写入的文件持续写入.
Paparazzi [jvm] 类Paparazzi@JvmOverloadsconstructor(environment:Environment= detectEnvironment(), deviceConfig:DeviceConfig= DeviceConfig.NEXUS_5, theme:String= “android:Theme.Material.NoActionBar.Fullscreen”, renderingMode: SessionParams.RenderingMode = RenderingMode.NORMAL, appCompatEnabled:Boolean= true, maxPercentDifference:Double= 0.1, snapshotHandler:SnapshotHandler= determineHandler(maxPercentDifference), renderExtensions:Set<RenderExtension> = setOf(), supportsRtl:Boolean= false) : TestRule
RenderExtension [jvm] 接口RenderExtension 用于在每个烘托帧顶部叠加附加信息的扩展.
Snapshot [jvm] @JsonClass(generateAdapter = true) data classSnapshot(val name:String?, val testName:TestName, val timestamp:Date, val tags:List<String> = listOf(), val file:String? = null)
SnapshotHandler [jvm] 接口SnapshotHandler:Closeable
SnapshotVerifier [jvm] 类SnapshotVerifier@JvmOverloadsconstructor(maxPercentDifference:Double, rootDirectory:File= File(“src/test/snapshots”)) :SnapshotHandler
TestName [jvm] 数据类TestName(val packageName:String, val className:String, val methodName:String)

函数

名称 简介
androidHome [jvm] funandroidHome():String
detectEnvironment [jvm] fundetectEnvironment():Environment