ไลบรารี 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
รันการทดสอบและสร้างรายงาน HTML ที่ sample/build/reports/paparazzi/
แสดงการทดสอบและสแน็ปช็อตทั้งหมด
./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
หากใช้ jetifier เพื่อโยกย้ายไลบรารีสนับสนุนให้เพิ่มสิ่งต่อไปนี้ไปยัง gradle.properties
ของคุณเพื่อยกเว้นการพึ่งพา Android ที่รวมอยู่
android.jetifier.ignorelist =android-base-common,common
เมื่อถ่ายภาพหน้าจอของแอนิเมชั่นลอตตี้คุณต้องบังคับให้ Lottie ไม่ทำงานบนเธรดพื้นหลังมิฉะนั้นปาปารัสซี่สามารถโยนข้อยกเว้น #494, #630
@Before
fun setup () {
LottieTask . EXECUTOR = Executor ( Runnable ::run)
}
คอมโพสิตบางอย่าง -เช่น GoogleMap()
-ตรวจสอบ LocalInspectionMode
เพื่อลัดวงจรไปยัง @Preview
-Safe 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 '
}
สแน็ปช็อตของเวอร์ชันการพัฒนามีอยู่ในที่เก็บ 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.