การทดสอบ Android
JUnit, Espresso, unit test, instrumented test, assertion
1JUnit คืออะไร?
JUnit คืออะไร?
คำตอบ
JUnit คือ framework สำหรับ unit testing สำหรับ Java และ Kotlin เป็นมาตรฐานสำหรับการเขียนและรัน test อัตโนมัติ JUnit 4 ใช้ annotation (@Test, @Before, @After) เพื่อกำหนด test และ lifecycle ของพวกมัน Test JUnit เร็วเพราะรันบน JVM ในเครื่องโดยไม่ต้องใช้ Android emulator
2annotation @Test ใช้สำหรับอะไร?
annotation @Test ใช้สำหรับอะไร?
คำตอบ
@Test ทำเครื่องหมายเมธอดเป็น unit test เมธอดจะถูกรันโดย test runner หากไม่มี @Test เมธอดจะถูกเพิกเฉย ตัวอย่าง: @Test fun testAddition() { assertEquals(4, 2 + 2) } แต่ละ @Test ต้องเป็นอิสระและไม่ขึ้นอยู่กับลำดับการรัน
3annotation @Before ใช้สำหรับอะไร?
annotation @Before ใช้สำหรับอะไร?
คำตอบ
@Before ทำเครื่องหมายเมธอดที่รัน ก่อน แต่ละ test (@Test) มีประโยชน์สำหรับการเริ่มต้นออบเจกต์ทั่วไป สร้าง mock รีเซ็ตสถานะ ตัวอย่าง: @Before fun setUp() { viewModel = MyViewModel() } หากคุณมี 5 test, @Before จะรัน 5 ครั้ง ทางเลือก: @BeforeClass สำหรับการรันครั้งเดียวก่อน test ทั้งหมด
annotation @After ใช้สำหรับอะไร?
assertion ใน testing คืออะไร?
+25 คำถามสัมภาษณ์
หัวข้อสัมภาษณ์ Android อื่นๆ
พื้นฐาน Android
UI และทรัพยากร Android
Lifecycle ของ Android
การนำทาง Android
การจัดการข้อมูล Android
Networking Android
Android Gradle
พื้นฐานภาษา Kotlin สำหรับ Android
Room Database
การทำงานเบื้องหลัง
Jetpack Compose
สิทธิ์และฟีเจอร์ของอุปกรณ์
Firebase สำหรับ Android
Android MVVM Architecture
เครือข่าย Android ขั้นสูง
Collections และ Operators ใน Kotlin
Kotlin Coroutines และ Flow
การฉีด Dependency ใน Android
Android MVI Architecture
Android Clean Architecture
Android Compose ขั้นสูง
Android Performance and Monitoring
Android Security and Privacy
Android CI/CD and Release
Android UX and Form Factors
Android Testing Advanced
เชี่ยวชาญ Android สำหรับการสัมภาษณ์ครั้งถัดไป
เข้าถึงคำถามทั้งหมด flashcards แบบทดสอบเทคนิค แบบฝึกหัด code review และตัวจำลองสัมภาษณ์
เริ่มใช้ฟรี