@@ -25,8 +25,8 @@ WiFiAnalyzer is an Android application for analyzing WiFi networks. It helps use
2525## Project Structure
2626
2727```
28- app/src/main/kotlin/ # Main source code
29- app/src/test/kotlin/ # Unit tests
28+ app/src/main/kotlin/ # Main application source code
29+ app/src/test/kotlin/ # Unit tests
3030app/src/androidTest/kotlin/ # Android instrumentation tests
3131```
3232
@@ -75,30 +75,44 @@ All new features and bug fixes MUST include unit tests.
7575
7676### Test File Naming
7777
78- Test files follow the pattern ` [ClassName]Test.kt `
78+ Test files use several patterns, including but not limited to:
79+ - ` [ClassName]Test.kt `
80+ - ` [ClassName]InstrumentedTest.kt `
81+ - ` [ClassName]IntegrationTest.kt `
82+ - ` [ClassName]ParameterizedTest.kt `
83+ - ` [ClassName]TestUtil.kt `
84+
85+ Use the pattern that best describes the test's purpose. Document any deviations from these patterns in your code or pull request to maintain clarity.
7986
8087### Test Structure (AAA Pattern)
8188
8289``` kotlin
8390@Test
84- fun testMethodName () {
91+ fun shouldReturnCorrectVersionNumber () {
8592 // Arrange: Set up test data and mocks
86-
8793 // Act: Execute the code being tested
88-
8994 // Assert: Verify the results
9095}
9196```
9297
9398### Testing Patterns Used
9499
95- ** Mockito with Kotlin extensions: **
100+ // Example imports for test files:
96101``` kotlin
97102import org.mockito.kotlin.mock
98103import org.mockito.kotlin.verify
99104import org.mockito.kotlin.whenever
100105```
101106
107+ // Example imports for assertions:
108+ ``` kotlin
109+ import org.assertj.core.api.Assertions.assertThat
110+
111+ assertThat(actual).isEqualTo(expected)
112+ assertThat(actual).isTrue
113+ assertThat(actual).isNotNull()
114+ ```
115+
102116** Test teardown pattern:**
103117``` kotlin
104118@After
@@ -107,13 +121,34 @@ fun tearDown() {
107121}
108122```
109123
110- ** Robolectric for Android components:**
124+ ** Robolectric for Android components (use RobolectricUtil helper) :**
111125``` kotlin
112- val activity = Robolectric
113- .buildActivity(MainActivity ::class .java)
114- .create()
115- .resume()
116- .get()
126+ import com.vrem.wifianalyzer.RobolectricUtil
127+
128+ private val mainActivity = RobolectricUtil .INSTANCE .activity
129+
130+ // For fragments:
131+ RobolectricUtil .INSTANCE .startFragment(fragment)
132+ ```
133+
134+ ## Android Instrumentation Test Conventions
135+
136+ - Instrumentation test files are located in ` app/src/androidTest/kotlin/ ` .
137+ - File names typically follow the pattern ` [ClassName]InstrumentedTest.kt ` .
138+ - Use the ` @RunWith(AndroidJUnit4::class) ` annotation for instrumentation tests.
139+ - Access UI components using Espresso or Robolectric as appropriate.
140+ - Example instrumentation test structure:
141+
142+ ``` kotlin
143+ @RunWith(AndroidJUnit4 ::class )
144+ class MainActivityInstrumentedTest {
145+ @Test
146+ fun shouldDisplayMainScreen () {
147+ // Arrange: Launch activity
148+ // Act: Interact with UI
149+ // Assert: Verify UI state
150+ }
151+ }
117152```
118153
119154## Build Commands
0 commit comments