Perpustakaan Android untuk membuat layar aplikasi Anda tanpa perangkat fisik atau emulator.
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 ()
}
}
}Lihat situs web proyek untuk dokumentasi dan API.
./gradlew sample:testDebug Menjalankan tes dan menghasilkan laporan HTML di sample/build/reports/paparazzi/ Menampilkan semua uji coba dan snapshot.
./gradlew sample:recordPaparazziDebug Menyimpan snapshot sebagai nilai emas ke lokasi yang dikontrol sumber yang telah ditentukan (default ke src/test/snapshots ).
./gradlew sample:verifyPaparazziDebug Menjalankan tes dan memverifikasi terhadap nilai-nilai emas yang sebelumnya direkam. Kegagalan menghasilkan diff pada sample/build/paparazzi/failures .
Untuk contoh lebih lanjut, lihat proyek sampel.
Disarankan Anda menggunakan GIT LFS untuk menyimpan snapshot Anda. Inilah pengaturan cepat:
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 .gitattributesDi CI, Anda mungkin mengatur sesuatu seperti:
$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 Jika menggunakan Jetifier untuk bermigrasi dari pustaka dukungan, tambahkan yang berikut ini ke gradle.properties Anda. Properti untuk mengecualikan dependensi Android yang dibundel.
android.jetifier.ignorelist =android-base-common,commonSaat mengambil tangkapan layar animasi Lottie, Anda perlu memaksa Lottie untuk tidak menjalankan latar belakang utas, jika tidak paparazzi dapat melempar pengecualian #494, #630.
@Before
fun setup () {
LottieTask . EXECUTOR = Executor ( Runnable ::run)
} Beberapa komposable -seperti GoogleMap() -periksa for LocalInspectionMode untuk hubung singkat ke @Preview -safab dapat dikomposisi.
Namun, paparazzi tidak mengatur LocalInspectionMode secara global untuk memastikan bahwa snapshot mewakili output produksi yang sebenarnya, mirip dengan cara mengesampingkan View.isInEditMode untuk tampilan warisan.
Sebagai solusi, kami merekomendasikan pembungkus yang dapat dikomposisi dalam komposisi khusus dengan CompositionLocalProvider dan mengatur LocalInspectionMode di sana.
@Test
fun inspectionModeView () {
paparazzi.snapshot(
CompositionLocalProvider ( LocalInspectionMode provides true ) {
YourComposable ()
}
)
}Log perubahan kami memiliki riwayat rilis.
Menggunakan Aplikasi Plugin:
buildscript {
repositories {
mavenCentral()
google()
}
dependencies {
classpath ' app.cash.paparazzi:paparazzi-gradle-plugin:1.3.5 '
}
}
apply plugin : ' app.cash.paparazzi 'Menggunakan plugin DSL:
plugins {
id ' app.cash.paparazzi ' version ' 1.3.5 '
} Snapshots dari versi pengembangan tersedia di repositori snapshots Sonatype.
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.