diff --git a/app/build.gradle b/app/build.gradle index 65e6d04..48c5a98 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,10 +13,16 @@ android { applicationId "pl.marianjureczko.poszukiwacz" minSdkVersion 23 targetSdkVersion 34 - versionCode 7 - versionName "0.7" - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + versionCode 8 + versionName "0.8" + testInstrumentationRunner "pl.marianjureczko.poszukiwacz.CustomTestRunner" manifestPlaceholders = [facebookToken: FACEBOOK_TOKEN] + javaCompileOptions { + annotationProcessorOptions { + // Ensure these options are set for androidTest as well + arguments += ["dagger.hilt.android.internal.disableAndroidSuperclassValidation": "true"] + } + } } composeOptions { kotlinCompilerExtensionVersion compose_version @@ -44,6 +50,10 @@ android { resValue "string", "photo_ad", "ca-app-pub-3940256099942544/6300978111" } } + kapt { + correctErrorTypes = true + showProcessorStats = true + } flavorDimensions "assets", "mode" productFlavors { classic { @@ -73,7 +83,13 @@ android { setIgnore(true) } } - + sourceSets { + androidTest { + manifest.srcFile 'src/androidTest/AndroidManifest.xml' + java.srcDirs = ['src/androidTest/java'] + res.srcDirs = ['src/androidTest/res'] + } + } compileOptions { sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 @@ -125,7 +141,8 @@ dependencies { implementation "androidx.navigation:navigation-compose:2.4.2" implementation "androidx.window:window-java:1.1.0" implementation "com.google.dagger:hilt-android:${hilt_version}" - kapt "com.google.dagger:hilt-compiler:${hilt_version}" + implementation 'com.google.ar:core:1.45.0' + kapt "com.google.dagger:hilt-android-compiler:${hilt_version}" implementation 'androidx.hilt:hilt-navigation-compose:1.1.0-alpha01' implementation 'com.google.accompanist:accompanist-permissions:0.30.1' implementation 'commons-io:commons-io:2.11.0' @@ -152,11 +169,17 @@ dependencies { androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test:core:1.4.0' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' + androidTestImplementation "androidx.test.espresso:espresso-intents:3.5.1" androidTestImplementation group: 'org.mockito', name: 'mockito-core', version: '4.4.0' androidTestImplementation 'org.mockito:mockito-inline:2.13.0' androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version" + androidTestImplementation 'androidx.test:rules:1.5.0' + androidTestImplementation 'androidx.test:runner:1.5.2' + androidTestImplementation "com.google.dagger:hilt-android-testing:${hilt_version}" + kaptAndroidTest "com.google.dagger:hilt-android-compiler:${hilt_version}" debugImplementation "androidx.compose.ui:ui-tooling:$compose_version" + debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version" } configurations { diff --git a/app/src/androidTest/assets/map_footer.png b/app/src/androidTest/assets/map_footer.png new file mode 100644 index 0000000..fab8e6b Binary files /dev/null and b/app/src/androidTest/assets/map_footer.png differ diff --git a/app/src/androidTest/assets/summary.png b/app/src/androidTest/assets/summary.png new file mode 100644 index 0000000..0d87003 Binary files /dev/null and b/app/src/androidTest/assets/summary.png differ diff --git a/app/src/androidTestKalinowiceCustomDebug/java/pl/marianjureczko/poszukiwacz/CustomTestRunner.kt b/app/src/androidTestKalinowiceCustomDebug/java/pl/marianjureczko/poszukiwacz/CustomTestRunner.kt new file mode 100644 index 0000000..19f4e3c --- /dev/null +++ b/app/src/androidTestKalinowiceCustomDebug/java/pl/marianjureczko/poszukiwacz/CustomTestRunner.kt @@ -0,0 +1,13 @@ +package pl.marianjureczko.poszukiwacz + +import android.app.Application +import android.content.Context +import androidx.test.runner.AndroidJUnitRunner +import dagger.hilt.android.testing.HiltTestApplication + +class CustomTestRunner : AndroidJUnitRunner() { + + override fun newApplication(cl: ClassLoader?, name: String?, context: Context?): Application { + return super.newApplication(cl, HiltTestApplication::class.java.name, context) + } +} diff --git a/app/src/androidTestKalinowiceCustomDebug/java/pl/marianjureczko/poszukiwacz/MyInstrumentedTest.kt b/app/src/androidTestKalinowiceCustomDebug/java/pl/marianjureczko/poszukiwacz/MyInstrumentedTest.kt new file mode 100644 index 0000000..75a1c19 --- /dev/null +++ b/app/src/androidTestKalinowiceCustomDebug/java/pl/marianjureczko/poszukiwacz/MyInstrumentedTest.kt @@ -0,0 +1,52 @@ +package pl.marianjureczko.poszukiwacz + +import androidx.compose.ui.test.assertCountEquals +import androidx.compose.ui.test.assertTextContains +import androidx.compose.ui.test.junit4.createAndroidComposeRule +import androidx.compose.ui.test.onAllNodesWithContentDescription +import androidx.test.rule.GrantPermissionRule +import dagger.hilt.android.testing.HiltAndroidRule +import dagger.hilt.android.testing.HiltAndroidTest +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import pl.marianjureczko.poszukiwacz.activity.main.MainActivity + +//@UninstallModules(SingletonModule::class) +@HiltAndroidTest +//@Config(application = HiltTestApplication::class) +class MyInstrumentedTest { + + + @get:Rule(order = 0) + val hiltRule = HiltAndroidRule(this) + + @get:Rule(order = 1) + val composeRule = createAndroidComposeRule() + + @get:Rule(order = 3) + val permissionRule: GrantPermissionRule = GrantPermissionRule.grant( + android.Manifest.permission.ACCESS_FINE_LOCATION, + android.Manifest.permission.CAMERA + ) + + @Before + fun init() { + hiltRule.inject() + } + + @Test + fun test() { + //given +// composeRule.waitForIdle() + val text = composeRule.onAllNodesWithContentDescription("TEST", false, false, true) + .assertCountEquals(1) + .get(0) + + //then + text.assertTextContains("WARNING", substring = true) + + + } + +} \ No newline at end of file diff --git a/app/src/custom/java/pl/marianjureczko/poszukiwacz/screen/main/MainScreenBody.kt b/app/src/custom/java/pl/marianjureczko/poszukiwacz/screen/main/MainScreenBody.kt index 8e1c201..1598841 100644 --- a/app/src/custom/java/pl/marianjureczko/poszukiwacz/screen/main/MainScreenBody.kt +++ b/app/src/custom/java/pl/marianjureczko/poszukiwacz/screen/main/MainScreenBody.kt @@ -24,6 +24,8 @@ import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.colorResource import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.semantics.contentDescription +import androidx.compose.ui.semantics.semantics import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel @@ -52,7 +54,8 @@ fun MainScreenBody(goToSearching: GoToSearching) { Text( text = state.messages[state.messageIndex].text, color = colorResource(R.color.colorPrimaryVariant), - textAlign = TextAlign.Justify + textAlign = TextAlign.Justify, + modifier = Modifier.semantics { contentDescription = "TEST" } ) Row( modifier = Modifier diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 07ba822..90375b7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + diff --git a/app/src/main/java/pl/marianjureczko/poszukiwacz/activity/main/MainActivity.kt b/app/src/main/java/pl/marianjureczko/poszukiwacz/activity/main/MainActivity.kt index 190dffc..0b92b0c 100644 --- a/app/src/main/java/pl/marianjureczko/poszukiwacz/activity/main/MainActivity.kt +++ b/app/src/main/java/pl/marianjureczko/poszukiwacz/activity/main/MainActivity.kt @@ -52,7 +52,6 @@ val FACEBOOK_ROUTE = "$FACEBOOK_PATH" /** * Routes creation and selection activity */ -//TODO t: check https://developer.android.com/build/build-variants and Product Flavours @AndroidEntryPoint class MainActivity : ComponentActivity() { private val TAG = javaClass.simpleName @@ -98,7 +97,7 @@ class MainActivity : ComponentActivity() { } @Composable -private fun ComposeRoot(onClickGuide: GoToGuide) { +fun ComposeRoot(onClickGuide: GoToGuide) { val navController = rememberNavController() val goToFacebook: GoToFacebook = FacebookHelper.createFacebookCallback(navController) val goToCommemorative: GoToCommemorative = { treasureId -> navController.navigate("$COMMEMORATIVE_PATH/$treasureId") } @@ -112,7 +111,6 @@ private fun ComposeRoot(onClickGuide: GoToGuide) { composable( route = SEARCHING_ROUTE, arguments = listOf(navArgument(PARAMETER_ROUTE_NAME) { type = NavType.StringType }), -// deepLinks = listOf(navDeepLink { uriPattern = "www.restaurantsapp.details.com/{restaurant_id}" }), ) { SearchingScreen( navController = navController, diff --git a/app/src/main/java/pl/marianjureczko/poszukiwacz/ui/components/AdvertBanner.kt b/app/src/main/java/pl/marianjureczko/poszukiwacz/ui/components/AdvertBanner.kt index 9754310..4b298bd 100644 --- a/app/src/main/java/pl/marianjureczko/poszukiwacz/ui/components/AdvertBanner.kt +++ b/app/src/main/java/pl/marianjureczko/poszukiwacz/ui/components/AdvertBanner.kt @@ -7,6 +7,8 @@ import androidx.compose.ui.viewinterop.AndroidView import com.google.android.gms.ads.AdRequest import com.google.android.gms.ads.AdSize import com.google.android.gms.ads.AdView +import com.google.android.gms.ads.MobileAds +import com.google.android.gms.ads.RequestConfiguration import pl.marianjureczko.poszukiwacz.R @Composable @@ -14,6 +16,15 @@ fun AdvertBanner(){ AndroidView( modifier = Modifier.fillMaxWidth(), factory = { context -> + MobileAds.setRequestConfiguration( + MobileAds.getRequestConfiguration() + .toBuilder() + .setTagForChildDirectedTreatment(RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE) + .setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE) + .setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_G) + .build() + ) + AdView(context).apply { setAdSize(AdSize.BANNER) adUnitId = context.resources.getString(R.string.main_ad) diff --git a/app/src/classicTest/java/pl/marianjureczko/poszukiwacz/activity/bluetooth/CancellableThreadTest.kt b/app/src/testClassic/java/pl/marianjureczko/poszukiwacz/activity/bluetooth/CancellableThreadTest.kt similarity index 100% rename from app/src/classicTest/java/pl/marianjureczko/poszukiwacz/activity/bluetooth/CancellableThreadTest.kt rename to app/src/testClassic/java/pl/marianjureczko/poszukiwacz/activity/bluetooth/CancellableThreadTest.kt diff --git a/app/src/classicTest/java/pl/marianjureczko/poszukiwacz/activity/searching/JustFoundFinderTest.kt b/app/src/testClassic/java/pl/marianjureczko/poszukiwacz/activity/searching/JustFoundFinderTest.kt similarity index 100% rename from app/src/classicTest/java/pl/marianjureczko/poszukiwacz/activity/searching/JustFoundFinderTest.kt rename to app/src/testClassic/java/pl/marianjureczko/poszukiwacz/activity/searching/JustFoundFinderTest.kt diff --git a/app/src/classicTest/java/pl/marianjureczko/poszukiwacz/activity/searching/SearchingActivityViewModelTest.kt b/app/src/testClassic/java/pl/marianjureczko/poszukiwacz/activity/searching/SearchingActivityViewModelTest.kt similarity index 100% rename from app/src/classicTest/java/pl/marianjureczko/poszukiwacz/activity/searching/SearchingActivityViewModelTest.kt rename to app/src/testClassic/java/pl/marianjureczko/poszukiwacz/activity/searching/SearchingActivityViewModelTest.kt diff --git a/app/src/classicTest/java/pl/marianjureczko/poszukiwacz/activity/treasureseditor/CoordinatesFormatterTest.kt b/app/src/testClassic/java/pl/marianjureczko/poszukiwacz/activity/treasureseditor/CoordinatesFormatterTest.kt similarity index 100% rename from app/src/classicTest/java/pl/marianjureczko/poszukiwacz/activity/treasureseditor/CoordinatesFormatterTest.kt rename to app/src/testClassic/java/pl/marianjureczko/poszukiwacz/activity/treasureseditor/CoordinatesFormatterTest.kt diff --git a/app/src/classicTest/java/pl/marianjureczko/poszukiwacz/activity/treasureseditor/TreasuresEditorViewModelTest.kt b/app/src/testClassic/java/pl/marianjureczko/poszukiwacz/activity/treasureseditor/TreasuresEditorViewModelTest.kt similarity index 100% rename from app/src/classicTest/java/pl/marianjureczko/poszukiwacz/activity/treasureseditor/TreasuresEditorViewModelTest.kt rename to app/src/testClassic/java/pl/marianjureczko/poszukiwacz/activity/treasureseditor/TreasuresEditorViewModelTest.kt diff --git a/app/src/classicTest/java/pl/marianjureczko/poszukiwacz/activity/treasureselector/SelectorViewModelTest.kt b/app/src/testClassic/java/pl/marianjureczko/poszukiwacz/activity/treasureselector/SelectorViewModelTest.kt similarity index 100% rename from app/src/classicTest/java/pl/marianjureczko/poszukiwacz/activity/treasureselector/SelectorViewModelTest.kt rename to app/src/testClassic/java/pl/marianjureczko/poszukiwacz/activity/treasureselector/SelectorViewModelTest.kt diff --git a/app/src/classicTest/java/pl/marianjureczko/poszukiwacz/permissions/PermissionManagerTest.kt b/app/src/testClassic/java/pl/marianjureczko/poszukiwacz/permissions/PermissionManagerTest.kt similarity index 100% rename from app/src/classicTest/java/pl/marianjureczko/poszukiwacz/permissions/PermissionManagerTest.kt rename to app/src/testClassic/java/pl/marianjureczko/poszukiwacz/permissions/PermissionManagerTest.kt diff --git a/app/src/classicTest/java/pl/marianjureczko/poszukiwacz/permissions/PermissionsFixture.kt b/app/src/testClassic/java/pl/marianjureczko/poszukiwacz/permissions/PermissionsFixture.kt similarity index 100% rename from app/src/classicTest/java/pl/marianjureczko/poszukiwacz/permissions/PermissionsFixture.kt rename to app/src/testClassic/java/pl/marianjureczko/poszukiwacz/permissions/PermissionsFixture.kt diff --git a/docs/development.md b/docs/development.md index 6be36a5..d72cacd 100644 --- a/docs/development.md +++ b/docs/development.md @@ -223,12 +223,20 @@ In order to refer to one of the variant, for instance to execute unit tests, one ``` $ ./gradlew testCustomDebugUnitTest ``` +The above line will execute tests from the "custom" flavors as well as from the "unflavoured" source set, i.e. src/test. + # Source sets For each flavor there has been created a source set with the same name as the flavor. -There are also dedicated test source sets with the `Test` postfix, i.e. `Test` +There are also dedicated test source sets with the `test` prefix, i.e. `test` Note that the source sets contains not only source code but also resources and assets. +The pattern is not followed for the instrumented UI tests. +For those tests, the source set directory name has and `androidTest` prefix followed by all flavors required to have a vaild build variant, e.g. `androidTestKalinowiceCustomDebug`. +In order to execute such tests you need and a running emulator, and then execute: +``` +$ ./gradlew connectedKalinowiceCustomDebugAndroidTest +``` # Releasing