Una biblioteca de Android para representar las pantallas de su aplicación sin un dispositivo físico o emulador.
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 ()
}
}
}
Consulte el sitio web del proyecto para la documentación y las API.
./gradlew sample:testDebug
Ejecuta pruebas y genera un informe HTML en sample/build/reports/paparazzi/
Mostrando todas las ejecuciones y instantáneas de prueba.
./gradlew sample:recordPaparazziDebug
Guarda instantáneas como valores dorados en una ubicación predefinida controlada por la fuente (predeterminada a src/test/snapshots
).
./gradlew sample:verifyPaparazziDebug
Ejecuta pruebas y verifica contra valores dorados previamente grabados. Las fallas generan diferencias en sample/build/paparazzi/failures
.
Para obtener más ejemplos, consulte el proyecto de muestra.
Se recomienda que use GIT LFS para almacenar sus instantáneas. Aquí hay una configuración rápida:
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
En CI, podría configurar algo como:
$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
Si usa el jetificador para migrar las bibliotecas de soporte, agregue lo siguiente a su gradle.properties
. Properties para excluir las dependencias de Android agrupadas.
android.jetifier.ignorelist =android-base-common,common
Al tomar capturas de pantalla de Lottie Animations, debe obligar a Lottie a no correr en un hilo de fondo, de lo contrario, los paparazzi pueden lanzar excepciones #494, #630.
@Before
fun setup () {
LottieTask . EXECUTOR = Executor ( Runnable ::run)
}
Algunos composibles, como GoogleMap()
, verifique si LocalInspectionMode
para cortocircuito a un compuesto @Preview
-Safe.
Sin embargo, Paparazzi no establece LocalInspectionMode
a nivel mundial para garantizar que la instantánea represente la verdadera salida de producción, similar a cómo anula View. View.isInEditMode
para vistas heredadas.
Como solución alternativa, recomendamos envolver dicho compuesto en un compuesto personalizado con un CompositionLocalProvider
y configurar LocalInspectionMode
allí.
@Test
fun inspectionModeView () {
paparazzi.snapshot(
CompositionLocalProvider ( LocalInspectionMode provides true ) {
YourComposable ()
}
)
}
Nuestro registro de cambios tiene historial de lanzamiento.
Uso de la aplicación Plugin:
buildscript {
repositories {
mavenCentral()
google()
}
dependencies {
classpath ' app.cash.paparazzi:paparazzi-gradle-plugin:1.3.5 '
}
}
apply plugin : ' app.cash.paparazzi '
Usando los complementos DSL:
plugins {
id ' app.cash.paparazzi ' version ' 1.3.5 '
}
Las instantáneas de la versión de desarrollo están disponibles en el repositorio snapshots
de 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.