物理デバイスまたはエミュレータなしでアプリケーション画面をレンダリングする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については、プロジェクトWebサイトを参照してください。
./gradlew sample:testDebugテストを実行し、 sample/build/reports/paparazzi/すべてのテストの実行とスナップショットを表示するHTMLレポートを生成します。
./gradlew sample:recordPaparazziDebugスナップショットを金色の値として定義されたソース制御の場所に保存します(デフォルトはsrc/test/snapshotsになります)。
./gradlew sample:verifyPaparazziDebugテストを実行し、以前に記録されたゴールデン値に対して検証します。障害はsample/build/paparazzi/failuresでdiffを生成します。
その他の例については、サンプルプロジェクトをご覧ください。
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 .gitattributesCIでは、次のようなものをセットアップできます。
$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を使用してサポートライブラリを移行する場合は、 gradle.propertiesに以下を追加して、バンドルされたAndroid依存関係を除外します。
android.jetifier.ignorelist =android-base-common,commonLottieアニメーションのスクリーンショットを撮影する場合、Lottieにバックグラウンドスレッドで実行されないように強制する必要があります。そうしないと、Paparazziは例外#494、#630を投げることができます。
@Before
fun setup () {
LottieTask . EXECUTOR = Executor ( Runnable ::run)
} GoogleMap()などの一部のコンポーネブル - @Preview -safe composableへの短絡するLocalInspectionModeを確認します。
ただし、Paparazziは、スナップView.isInEditModeビューをオーバーライドする方法と同様に、スナップショットが真の生産出力を表すことを保証するために、グローバルにLocalInspectionMode設定していません。
回避策として、 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.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.