paparazzi
1.3.5
一个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 ()
}
}
}请参阅项目网站以获取文档和API。
./gradlew sample:testDebug运行测试并在sample/build/reports/paparazzi/显示所有测试运行和快照上生成HTML报告。
./gradlew sample:recordPaparazziDebug将快照作为黄金值保存到预定义的源控制位置(默认为src/test/snapshots )。
./gradlew sample:verifyPaparazziDebug运行测试并验证先前录制的黄金值。故障在sample/build/paparazzi/failures时产生差异。
有关更多示例,请查看示例项目。
建议您使用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 如果使用喷射器迁移支持库,请将以下内容添加到您的gradle.properties中。
android.jetifier.ignorelist =android-base-common,common在拍摄Lottie动画的屏幕截图时,您需要强迫Lottie不在背景线程上,否则狗仔队可以投掷异常#494,#630。
@Before
fun setup () {
LottieTask . EXECUTOR = Executor ( Runnable ::run)
}一些组合(例如GoogleMap() - 检查LocalInspectionMode to @Preview -Saft -Saf composable。
但是,狗仔队在全球范围内没有设置LocalInspectionMode ,以确保快照代表真实的生产输出,类似于其覆盖View.isInEditMode方式。
作为解决方法,我们建议将这样的合并包装在可CompositionLocalProvider的组合中,并在其中设置LocalInspectionMode 。
@Test
fun inspectionModeView () {
paparazzi.snapshot(
CompositionLocalProvider ( LocalInspectionMode provides true ) {
YourComposable ()
}
)
}我们的更改日志具有发布历史记录。
使用插件应用程序:
buildscript {
repositories {
mavenCentral()
google()
}
dependencies {
classpath ' app.cash.paparazzi:paparazzi-gradle-plugin:1.3.5 '
}
}
apply plugin : ' app.cash.paparazzi '使用插件DSL:
plugins {
id ' app.cash.paparazzi ' version ' 1.3.5 '
}开发版本的快照可在Sonatype的snapshots存储库中获得。
repositories {
// ...
maven {
url ' https://oss.sonatype.org/content/repositories/snapshots/ '
}
} Copyright 2019 Square, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.