{
"items": [
{
"majorId": "01",
"majorName": "공공"
},
{
"majorId": "02",
"majorName": "음식"
},
{
"majorId": "03",
"majorName": "숙박"
},
{
"majorId": "04",
"majorName": "생활"
},
...
]
}
데이터소스 코드 작성 중(datasource > remote > guide_yongsan_remote_data_source_test.dart
)
group('getMajorCategory', () {
final tFixture = fixture('major_category.json');
final majorCategories = jsonDecode(tFixture)['items'];
List<MajorCategoryModel> majorCategoryList = [];
for (var majorCategory in majorCategories) {
majorCategoryList.add(MajorCategoryModel.fromJson(majorCategory));
}
test('should return major category when status code is 200', () async {
// arrange
setupMockHttpSuccess200(mockHttpClient, tFixture);
// act
final result = await dataSource.getMajorCategory();
// assert
expect(result, majorCategoryList);
// expect(result, isA<List<MajorCategoryModel>>());
});
});
}
다트의 json.decode 메서드는 Latin encoder를 사용 json에 영문자가 아닌 한글이들어가있어서 발생했던 에러
링크: https://stackoverflow.com/questions/61345133/flutter-unittestinvalid-argument-string-contains-invalid-characters
응답 헤더에 utf-8을 적용시켜 주어야함
(_) async => http.Response(
fixture('venues_details.json'),
200,
headers: {
HttpHeaders.contentTypeHeader: 'application/json; charset=utf-8',
}
)
class MockRemoteDataSource extends Mock
implements GuideYongsanRemoteDataSource {}
class MockLocalDataSource extends Mock implements GuideYongsanLocalDataSource {}
class MockNetworkInfo extends Mock implements NetworkInfo {}
void main() {
late GuideYongsanRepositoryImpl repository;
late MockRemoteDataSource mockRemoteDataSource;
late MockLocalDataSource mockLocalDataSource;
late MockNetworkInfo mockNetworkInfo;
setUp(() {
mockRemoteDataSource = MockRemoteDataSource();
mockLocalDataSource = MockLocalDataSource();
mockNetworkInfo = MockNetworkInfo();
repository = GuideYongsanRepositoryImpl(
remoteDataSource: mockRemoteDataSource,
localDataSource: mockLocalDataSource,
networkInfo: mockNetworkInfo);
// 네임드 파라미터를 쓸 경우 테스트 코드에서 인자를 any()로 전달해서 테스트할 수 없음
when(() => mockLocalDataSource.cacheYongsanRemoteData(any(), any()))
.thenAnswer((_) => Future.value()); // OK
when(() => mockLocalDataSource.cacheYongsanRemoteData(
listNameForCaching: any(), // The named parameter 'listNameForCaching' isn't defined.
yongsanRemoteData: any())).thenAnswer((_) => Future.value()); // The named parameter 'yongsanRemoteData' isn't defined.
});
https://cishome.tistory.com/264
링크처럼 안드로이드 패키지명이
app/src/main/AndroidManifest.xml
> manifest태그 내에 없을 수 있음
android/app/build.gradle
요 경로 확인
// android/app/build.gradle
android {
namespace "com.example.guide_yongsan"
// compileSdkVersion flutter.compileSdkVersion
compileSdkVersion 34
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}