Android

Android Testing

JUnit, Espresso, unit tests, instrumented tests, assertions

28 面接問題·
Junior
1

What is JUnit?

回答

JUnit is a unit testing framework for Java and Kotlin. It's the standard for writing and executing automated tests. JUnit 4 uses annotations (@Test, @Before, @After) to define tests and their lifecycle. JUnit tests are fast because they run on the local JVM without Android emulator.

2

What is the @Test annotation used for?

回答

@Test marks a method as a unit test. The method will be executed by the test runner. Without @Test, the method is ignored. Example: @Test fun testAddition() { assertEquals(4, 2 + 2) }. Each @Test must be independent and not depend on execution order.

3

What is the @Before annotation used for?

回答

@Before marks a method that executes BEFORE each test (@Test). Useful for initializing common objects, creating mocks, resetting state. Example: @Before fun setUp() { viewModel = MyViewModel() }. If you have 5 tests, @Before runs 5 times. Alternative: @BeforeClass for single execution before all tests.

4

What is the @After annotation used for?

5

What is an assertion in testing?

+25 面接問題

次の面接に向けてAndroidをマスター

すべての問題、flashcards、技術テスト、コードレビュー演習、面接シミュレーターにアクセス。

無料で始める