의도가 다른 UT 예제를 보았지만 UT를 내 앱에 통합하는 실용적인 방법을 찾지 못했습니다.Unit Testing (Android) - 테스트 할 일반적인 시나리오
JSON 피드 및 게시물 데이터를 읽을 수있는 간단한 활동을 고려해보십시오.
public class MainActivity extends Activity {
String dataArray;
/** Called when the activity is first created. */
public void onCreate() {
//Get json data from the server
getAPIdata();
}
/** get data json from the server */
public getAPIdata(Server Response){
//Parse the json output
//Validate
//populate data array
return dataArray;
}
/** use populated data array and display */
public setListView(dataArray){
//use the data array and set a list view to display the results
}
/** post data to create a record */
public postDataToServer(Parameters){
//validate input data
//send a post request to the server
//if success, print a success message on the screen
//else print the error
}
}
이것은 주로 Android 애플리케이션에있는 구조입니다. 나는 많은 비즈니스 논리가 없다.
다시 요약 해 보겠습니다.
JSON 검색 및 디스플레이 지금이 응용 프로그램은 볼 수
그래서 편집 기록을 작성하는 API로
폼 입력 검증
POST 데이터 결과/주로 CRUD 작업을 처리합니다. 제 질문은 당신입니까?
이 응용 프로그램에서 UT를 어떻게 사용할 수 있습니까? (또는 비즈니스 로직이 많지 않으므로 여기서는 UT가 필요하지 않습니다.)
실용적인 제안은 인정 될 것입니다.
미리 감사드립니다.
1 단계 : 우려 사항을 분리합니다. 활동은 json 데이터 다운로드를 관리하지 않아야합니다. 논리가 다른 클래스로 나뉘어져 있습니다. –
실제로 제가 말씀 드린 바와 같이 별도의 클래스에 있습니다. 매우 길기 때문에 전체 코드를 게시하지 않았습니다. –