Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[경북대 Android_유지예] 4주차과제_Step2_테스트수정 #103

Open
wants to merge 33 commits into
base: yjy1220
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
550d7da
docs: readme.md
Jul 15, 2024
8109bd9
docs:readme.md
Jul 15, 2024
54ed5c5
build: kt files
Jul 15, 2024
05e8a8e
feat: layout files
Jul 15, 2024
90f15a8
feat: androidmanifest.xml
Jul 15, 2024
37eba3d
build: build files
Jul 15, 2024
8b53bca
chore: constants.kt apikey
Jul 15, 2024
82e9893
docs: readme.md
Jul 16, 2024
82fbe05
build: dependencies
Jul 16, 2024
c9fdce2
feat: research with selected word
Jul 16, 2024
18b0a06
feat: error page with api key
Jul 16, 2024
c1eaf3c
docs: readme.me
Jul 16, 2024
847347b
feat: bottomsheet
Jul 16, 2024
9b83742
chore: bottomsheet init
Jul 16, 2024
c702aa3
feat: marker add with label
Jul 16, 2024
f1b837e
feat: marker with bottomsheet information
Jul 16, 2024
9fb873a
feat: Search->Main->Search selected word store
Jul 16, 2024
555b806
fix: bottomsheet hidden when first map
Jul 16, 2024
aa56470
chore: change the marker.png size
Jul 16, 2024
637765e
docs: readme.md until video
Jul 16, 2024
0181916
feat: saved location
Jul 16, 2024
41c0933
Merge branch 'yjy1220' into feat-JiyeYU-1
YJY1220 Jul 16, 2024
5181987
docs: readme.md
Jul 18, 2024
fd63ac3
feat: basic functest code
Jul 18, 2024
f15aa93
feat: functest-search
Jul 18, 2024
084d6c4
feat: functest - recyclerview searched list
Jul 18, 2024
1c3069e
feat: functest-marker&bottomsheet
Jul 18, 2024
3a0d5b9
feat: functest - load lastLocatioin and reload with map
Jul 18, 2024
e3913e2
feat: selected word check and click with search
Jul 18, 2024
f94f7c1
feat: basic error test code
Jul 18, 2024
bca288f
feat: error test - layout view
Jul 18, 2024
6f1f27d
docs: readme.md
Jul 18, 2024
82353f9
feat: ViewModelTest & RepositoryTest - unittest
Jul 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
# android-map-location
## KakaoTechCampus 2기 Step2 4주차 과제 : 위치이동 - 테스트

### 0단계 - 코드 구성
### Step2. 테스트 기능 구현
- [ ] 검색 기능 테스트
- [ ] 검색 결과 보이는지 테스트 - RecyclerView로 표시
- [ ] 해당 검색 결과 중 하나 눌러서 지도 마커로 표시 및 bottomsheet로 정보 표시
- [ ] 마지막 위치 저장 후 다시 앱 실행 시 해당 위치로 지도 표시
- [ ] 저장된 검색어 남아있는지 확인 후 해당 저장된 검색어 클릭 시 재검색 확인
- [ ] api키 오류 시 에러화면 표시 확인


### 테스트 성공 화면
- Function Test Success
<img src="https://github.com/user-attachments/assets/9dc0b904-f397-4b69-93cc-387cf29c4048"/>
- ErrorScreen Test Success
<img src="https://github.com/user-attachments/assets/50f75bb3-e4d6-4fb2-ac9d-35e6cea6dc37"/>


18 changes: 14 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,23 @@ dependencies {
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
implementation("com.squareup.okhttp3:logging-interceptor:4.9.0")
implementation("com.kakao.sdk:v2-user:2.10.0") // Kakao SDK 추가
implementation("com.kakao.sdk:v2-user:2.10.0")
implementation("com.kakao.maps.open:android:2.9.5")
implementation("androidx.activity:activity:1.8.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
implementation("androidx.fragment:fragment-ktx:1.3.6")
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.3.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1")
implementation("com.google.android.gms:play-services-maps:19.0.0")
implementation("com.google.android.material:material:1.11.0")
testImplementation("junit:junit:4.13.2")
testImplementation("org.mockito:mockito-core:3.11.2")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.5.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation("androidx.test:core-ktx:1.4.0")
androidTestImplementation("androidx.test:runner:1.4.0")
androidTestImplementation("androidx.test:rules:1.4.0")
androidTestImplementation("org.mockito:mockito-core:3.11.2")
androidTestImplementation("org.mockito:mockito-android:3.11.2")
androidTestImplementation("androidx.arch.core:core-testing:2.1.0")
}
47 changes: 47 additions & 0 deletions app/src/androidTest/java/campus/tech/kakao/map/ErrorScreenTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package campus.tech.kakao.map

import android.content.Context
import android.view.View
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import campus.tech.kakao.map.ui.MainActivity
import org.junit.*
import org.junit.runner.RunWith
import org.junit.Assert.assertTrue

@RunWith(AndroidJUnit4::class)
class ErrorScreenTest {

private lateinit var scenario: ActivityScenario<MainActivity>
private lateinit var context: Context

@Before
fun setUp() {
context = InstrumentationRegistry.getInstrumentation().targetContext
scenario = ActivityScenario.launch(MainActivity::class.java)
}

@After
fun tearDown() {
if (::scenario.isInitialized) {
scenario.close()
}
}

@Test
fun testShowErrorScreen() {
scenario.onActivity { activity ->

Thread.sleep(2000)

val errorLayout: RelativeLayout = activity.findViewById(R.id.error_layout)
val errorDetails: TextView = activity.findViewById(R.id.error_details)

assertTrue(errorLayout.visibility == View.VISIBLE)
assertTrue(errorDetails.text.toString().contains("Unauthorized"))
}
}
}
160 changes: 160 additions & 0 deletions app/src/androidTest/java/campus/tech/kakao/map/FunctionTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package campus.tech.kakao.map

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.view.View
import android.widget.EditText
import android.widget.FrameLayout
import android.widget.TextView
import androidx.lifecycle.MutableLiveData
import androidx.recyclerview.widget.RecyclerView
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import campus.tech.kakao.map.model.MapItem
import campus.tech.kakao.map.ui.MainActivity
import campus.tech.kakao.map.ui.SearchActivity
import org.junit.*
import org.junit.runner.RunWith
import org.junit.Assert.assertEquals
import java.util.concurrent.Executors

@RunWith(AndroidJUnit4::class)
class FunctionTest {

private lateinit var scenarioMain: ActivityScenario<MainActivity>
private lateinit var scenarioSearch: ActivityScenario<SearchActivity>
private lateinit var context: Context

@Before
fun setUp() {
context = InstrumentationRegistry.getInstrumentation().targetContext
scenarioMain = ActivityScenario.launch(MainActivity::class.java)
}

@After
fun tearDown() {
scenarioMain.close()
if (::scenarioSearch.isInitialized) {
scenarioSearch.close()
}
}

@Test
fun testCompleteFlow() {
scenarioMain.onActivity { mainActivity ->

val searchEditText: EditText = mainActivity.findViewById(R.id.search_edit_text)
searchEditText.performClick()

Executors.newSingleThreadExecutor().execute {
scenarioSearch = ActivityScenario.launch(SearchActivity::class.java)
scenarioSearch.onActivity { searchActivity ->
//1 검색 기능 테스트
val searchEditText: EditText = searchActivity.findViewById(R.id.searchEditText)
searchEditText.setText("바다 정원")
searchActivity.performSearch("바다 정원")

//2 recyclerview로 검색결과 보이는지 테스트
val searchResults = MutableLiveData<List<MapItem>>()
searchResults.postValue(
listOf(
MapItem(
"1",
"바다 정원",
"강원도 고성군",
"카페",
127.0,
37.0
)
)
)
searchActivity.viewModel.setSearchResults(searchResults.value ?: emptyList())

val searchResultsRecyclerView: RecyclerView =
searchActivity.findViewById(R.id.searchResultsRecyclerView)
searchResultsRecyclerView.adapter?.notifyDataSetChanged()
assertEquals(1, searchResultsRecyclerView.adapter?.itemCount)

//3. 해당 검색결과 중 하나 눌러서 지도 마커표시, bottomsheet 정보 표시
searchResultsRecyclerView.findViewHolderForAdapterPosition(0)?.itemView?.performClick()

searchActivity.setResultAndFinish(
MapItem(
"0",
"바다 정원",
"강원도 고성군",
"카페",
127.0,
37.0
)
)
val resultIntent = Intent().apply {
putExtra("place_name", "바다 정원")
putExtra("road_address_name", "강원도 고성군")
putExtra("x", 127.0)
putExtra("y", 37.0)
}

mainActivity.onActivityResult(
MainActivity.SEARCH_REQUEST_CODE,
Activity.RESULT_OK,
resultIntent
)
val bottomSheetTitle: TextView =
mainActivity.findViewById(R.id.bottomSheetTitle)
val bottomSheetAddress: TextView =
mainActivity.findViewById(R.id.bottomSheetAddress)
assertEquals("바다 정원", bottomSheetTitle.text.toString())
assertEquals("강원도 고성군", bottomSheetAddress.text.toString())

// 4. 마지막 위치 저장해서 다시 앱 실행시 해당 위치로 지도 뜨도록 하기
mainActivity.saveLastMarkerPosition(37.0, 127.0, "바다 정원", "강원도 고성군")
}

scenarioMain.recreate()
scenarioMain.onActivity { activity ->
activity.loadLastMarkerPosition()

val bottomSheetTitle: TextView = activity.findViewById(R.id.bottomSheetTitle)
val bottomSheetAddress: TextView =
activity.findViewById(R.id.bottomSheetAddress)
assertEquals("바다 정원", bottomSheetTitle.text.toString())
assertEquals("강원도 고성군", bottomSheetAddress.text.toString())
assertEquals(
View.VISIBLE,
activity.findViewById<FrameLayout>(R.id.bottomSheetLayout).visibility
)

// 5. searchactivity에서 저장된 검색어 남아있는지 확인하고 해당 검색어 누르면 해당 검색어로 재검색되는지 확인하기
val searchEditText: EditText = activity.findViewById(R.id.search_edit_text)
searchEditText.performClick()

Executors.newSingleThreadExecutor().execute {
scenarioSearch = ActivityScenario.launch(SearchActivity::class.java)
scenarioSearch.onActivity { searchActivity ->

val selectedItemsRecyclerView: RecyclerView =
searchActivity.findViewById(R.id.selectedItemsRecyclerView)
assertEquals(1, selectedItemsRecyclerView.adapter?.itemCount)
val selectedViewHolder =
selectedItemsRecyclerView.findViewHolderForAdapterPosition(0)
assertEquals(
"바다 정원",
selectedViewHolder?.itemView?.findViewById<TextView>(R.id.selectedItemName)?.text.toString()
)

selectedViewHolder?.itemView?.performClick()
searchActivity.performSearch("바다 정원")

val searchResultsRecyclerView: RecyclerView =
searchActivity.findViewById(R.id.searchResultsRecyclerView)
assertEquals(1, searchResultsRecyclerView.adapter?.itemCount)
}
}
}
}
}
}
}
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
android:value="@string/kakao_api_key" />

<activity
android:name=".MainActivity"
android:name=".ui.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -32,7 +32,7 @@
</intent-filter>
</activity>

<activity android:name=".SearchActivity" />
<activity android:name=".ui.SearchActivity" />
</application>

</manifest>
53 changes: 0 additions & 53 deletions app/src/main/java/campus/tech/kakao/map/MainActivity.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.model

//MapItem 넘겨받기 -> 매핑
data class KakaoSearchResponse(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.model

//이름 보다 알기 쉽게 변경 - api맞춰서
data class MapItem(
val id: String,
val place_name: String,
val road_address_name: String,
val category_group_name: String
val category_group_name: String,
val x: Double,
val y: Double

)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.network

import campus.tech.kakao.map.model.KakaoSearchResponse
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Header
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.network

import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.repository

import android.content.Context
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import android.util.Log
import campus.tech.kakao.map.util.Constants
import campus.tech.kakao.map.model.MapItem
import campus.tech.kakao.map.network.RetrofitInstance

class MapAccess(context: Context) {

Expand All @@ -12,7 +15,8 @@ class MapAccess(context: Context) {

return withContext(Dispatchers.IO) {

val apiKey = "KakaoAK ${BuildConfig.KAKAO_REST_API_KEY}"
val apiKey = Constants.KAKAO_API_KEY


val response = RetrofitInstance.api.searchPlaces(apiKey, query, page, size)

Expand Down
Loading