一个用于在没有物理设备或模拟器的情况下渲染应用程序界面的 Android 库。
class LaunchViewTest { @get:Rule val paparazzi = Paparazzi( deviceConfig = PIXEL_5, theme = "android:Theme.Material.Light.NoActionBar" // ...更多选项请参阅文档 ) @Test fun launchView() { val view = paparazzi.inflate<LaunchView>(R.layout.launch) // 或者... // 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 生成差异。
更多示例,请查看 sample 项目。
建议使用 Git LFS 来存储快照。以下是快速设置:
brew install git-lfs git config core.hooksPath # 可选,确认 git 钩子的安装位置 git lfs install --local git lfs track "**/snapshots/**/*.png" git add .gitattributes
在 CI 上,你可以设置类似以下内容:
$HOOKS_DIR/pre-receive
# 比较 .gitattributes 过滤器匹配的文件与实际由 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 "此远程仓库检测到文件提交时未使用 Git LFS。运行 'brew install git-lfs && git lfs install' 安装并重新提交文件。"; exit 1; fi
your_build_script.sh
if [[ 正在运行快照测试 ]]; then # 如果文件未使用 git lfs 提交,则快速失败 "$HOOKS_DIR"/pre-receive git lfs install --local git lfs pull fi
如果使用 Jetifier 迁移 Support 库,请在 gradle.properties 中添加以下内容以排除捆绑的 Android 依赖项。
android.jetifier.ignorelist=android-base-common,common
在对 Lottie 动画进行截图时,需要强制 Lottie 不在后台线程上运行,否则 Paparazzi 可能会抛出异常 #494,#630。
@Before fun setup() { LottieTask.EXECUTOR = Executor(Runnable::run) }
某些 Composable(如 GoogleMap())会检查 LocalInspectionMode 以快速切换到适用于 @Preview 的 Composable。
然而,Paparazzi 不会全局设置 LocalInspectionMode,以确保快照代表真实的生产输出,类似于它覆盖传统视图的 View.isInEditMode。
作为解决方案,我们建议将这样的 Composable 包装在带有 CompositionLocalProvider 的自定义 Composable 中,并在那里设置 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.4' } } apply plugin: 'app.cash.paparazzi'
使用插件 DSL:
plugins { id 'app.cash.paparazzi' version '1.3.4' }
开发版本的快照可在 Sonatype 的 snapshots 仓库中获取snap。
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.


能听懂你表达的视频模型
Seedance two是基于seedance2.0的中国大模型,支持图像、视频、音频、文本四种模态输入,表达方式更丰富,生成也更可控。


国内直接访问,限时3折
输入简单文字,生成想要的图片,纳米香蕉中文站基于 Google 模型的 AI 图片生成网站,支持文字生图、图生图。官网价格限时3折活动


职场AI,就用扣子
AI办公助手,复杂任务高效处理。办公效率低?扣子空间AI助手支持播客生成、PPT制作、网页开发及报告写作,覆盖科研、商业、舆情等领域的专家Agent 7x24小时响应,生活工作无缝切换,提升50%效率!


多风格AI绘画神器
堆友平台由阿里巴巴设计团队创建,作为一款AI驱动的设计工具,专为设计师提供一站式增长服务。功能覆盖海量3D素材、AI绘画、实时渲染以及专业抠图,显著提升设计品质和效率。平台不仅提供工具,还是一个促进创意交流和个人发展的空间,界面友好,适合所有级别的设计师和创意工作者。


零代码AI应用开发平台
零代码AI应用开发平台,用户只需一句话简单描述需求,AI能自动生成小程序、APP或H5网页应用,无需编写代码。

