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.