diff options
author | David Jia <davidjia@google.com> | 2024-02-26 23:28:09 +0000 |
---|---|---|
committer | David Jia <davidjia@google.com> | 2024-04-06 19:54:10 +0000 |
commit | e0e584da1aae1e081c14b605d29f61c9041704c2 (patch) | |
tree | d88d2b25134d44f217158540da2451471b0721eb | |
parent | 1fbcf3a6c408393401786a876009fe9d18844c31 (diff) | |
download | jetpack-camera-app-e0e584da1aae1e081c14b605d29f61c9041704c2.tar.gz |
[external/jetpack-camera-app] Turn tests into android_test modules
Test: Compiled each individual android_library or android_app module to
make sure the android_app module that is instrumented for them run
successfully.
Bug: 328101457
Change-Id: Id8bc905674affd123b97978978351cac6560b24e
-rw-r--r-- | Android.bp | 17 | ||||
-rw-r--r-- | TEST_MAPPING | 14 | ||||
-rw-r--r-- | app/src/androidTest/Android.bp | 24 | ||||
-rw-r--r-- | app/src/androidTest/AndroidManifest.xml | 30 | ||||
-rw-r--r-- | app/src/androidTest/AndroidTest.xml | 27 | ||||
-rw-r--r-- | domain/camera/src/test/Android.bp | 18 | ||||
-rw-r--r-- | domain/camera/src/test/AndroidManifest.xml | 30 | ||||
-rw-r--r-- | domain/camera/src/test/java/com/google/jetpackcamera/domain/camera/test/FakeCameraUseCaseTest.kt | 3 | ||||
-rw-r--r-- | feature/preview/src/androidTest/Android.bp | 25 | ||||
-rw-r--r-- | feature/preview/src/androidTest/AndroidManifest.xml | 32 | ||||
-rw-r--r-- | feature/preview/src/androidTest/AndroidTest.xml | 29 | ||||
-rw-r--r-- | feature/preview/src/test/java/com/google/jetpackcamera/feature/preview/PreviewViewModelTest.kt | 16 | ||||
-rw-r--r-- | feature/preview/src/test/java/com/google/jetpackcamera/feature/preview/ScreenFlashTest.kt | 4 | ||||
-rw-r--r-- | feature/settings/src/androidTest/Android.bp | 22 | ||||
-rw-r--r-- | feature/settings/src/androidTest/AndroidManifest.xml | 32 | ||||
-rw-r--r-- | feature/settings/src/androidTest/AndroidTest.xml | 28 |
16 files changed, 331 insertions, 20 deletions
@@ -2,16 +2,15 @@ package { default_applicable_licenses: [ "Android-Apache-2.0", ], + default_team: "trendy_team_camerax", } subdirs = [ - "app", - "core/common", - "camera-viewfinder-compose", - "data/settings", - "domain/camera", - "feature", - - ] - + "app", + "core/common", + "camera-viewfinder-compose", + "data/settings", + "domain/camera", + "feature", +] diff --git a/TEST_MAPPING b/TEST_MAPPING new file mode 100644 index 0000000..350127f --- /dev/null +++ b/TEST_MAPPING @@ -0,0 +1,14 @@ +{ + "postsubmit": [ + { + "name": "jetpack-camera-app-tests" + }, + { + "name": "jetpack-camera-app_feature_preview-androidtests" + }, + { + "name": "jetpack-camera-app_feature_settings-tests" + } + ] + +} diff --git a/app/src/androidTest/Android.bp b/app/src/androidTest/Android.bp new file mode 100644 index 0000000..1b20b12 --- /dev/null +++ b/app/src/androidTest/Android.bp @@ -0,0 +1,24 @@ +package { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +android_test { + name: "jetpack-camera-app-tests", + team: "trendy_team_camerax", + srcs: ["java/**/*.kt"], + static_libs: [ + "androidx.test.runner", + "androidx.test.uiautomator_uiautomator", + "androidx.test.espresso.core", + "androidx.test.ext.junit", + "androidx.test.rules", + "kotlinx_coroutines_test", + + ], + instrumentation_for: "jetpack-camera-app", + sdk_version: "34", + test_suites: ["general-tests"], + optimize: { + enabled: false, + }, +} diff --git a/app/src/androidTest/AndroidManifest.xml b/app/src/androidTest/AndroidManifest.xml new file mode 100644 index 0000000..5979338 --- /dev/null +++ b/app/src/androidTest/AndroidManifest.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2015 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.google.jetpackcamera.test" > + + <instrumentation + android:name="androidx.test.runner.AndroidJUnitRunner" + android:label="App Android Tests" + android:targetPackage="com.google.jetpackcamera" /> + + <application> + <uses-library android:name="android.test.runner" /> + </application> + +</manifest> diff --git a/app/src/androidTest/AndroidTest.xml b/app/src/androidTest/AndroidTest.xml new file mode 100644 index 0000000..9bc1535 --- /dev/null +++ b/app/src/androidTest/AndroidTest.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2024 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<configuration description="Runs App Test Cases."> + <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller"> + <option name="cleanup-apks" value="true" /> + <option name="test-file-name" value="jetpack-camera-app-tests.apk" /> + </target_preparer> + + <option name="test-tag" value="jetpack-camera-app-tests" /> + <test class="com.android.tradefed.testtype.AndroidJUnitTest" > + <option name="package" value="com.google.jetpackcamera.test" /> + <option name="runner" value="androidx.test.runner.AndroidJUnitRunner" /> + </test> +</configuration> diff --git a/domain/camera/src/test/Android.bp b/domain/camera/src/test/Android.bp new file mode 100644 index 0000000..cb1318a --- /dev/null +++ b/domain/camera/src/test/Android.bp @@ -0,0 +1,18 @@ +package { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +java_test { + name: "jetpack-camera-app_domain_camera-tests", + team: "trendy_team_camerax", + srcs: ["java/**/*.kt"], + static_libs: [ + "androidx.test.runner", + "kotlinx_coroutines_test", + "androidx.test.ext.junit", + "mockito-core", + "jetpack-camera-app_domain_camera", + + ], + min_sdk_version: "21", +} diff --git a/domain/camera/src/test/AndroidManifest.xml b/domain/camera/src/test/AndroidManifest.xml new file mode 100644 index 0000000..e84b7b1 --- /dev/null +++ b/domain/camera/src/test/AndroidManifest.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2015 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.google.jetpackcamera.domain.camera.test" > + + <instrumentation + android:name="androidx.test.runner.AndroidJUnitRunner" + android:label="Domain Camera Unit Tests" + android:targetPackage="com.google.jetpackcamera.domain.camera" /> + + <application> + <uses-library android:name="android.test.runner" /> + </application> + +</manifest> diff --git a/domain/camera/src/test/java/com/google/jetpackcamera/domain/camera/test/FakeCameraUseCaseTest.kt b/domain/camera/src/test/java/com/google/jetpackcamera/domain/camera/test/FakeCameraUseCaseTest.kt index 646d110..26c81d7 100644 --- a/domain/camera/src/test/java/com/google/jetpackcamera/domain/camera/test/FakeCameraUseCaseTest.kt +++ b/domain/camera/src/test/java/com/google/jetpackcamera/domain/camera/test/FakeCameraUseCaseTest.kt @@ -43,7 +43,8 @@ class FakeCameraUseCaseTest { private val cameraUseCase = FakeCameraUseCase(testScope) - private val surfaceProvider: Preview.SurfaceProvider = Mockito.mock() + private val surfaceProvider: Preview.SurfaceProvider = + Mockito.mock(Preview.SurfaceProvider::class.java) @Before fun setup() = runTest(testDispatcher) { diff --git a/feature/preview/src/androidTest/Android.bp b/feature/preview/src/androidTest/Android.bp new file mode 100644 index 0000000..b61e291 --- /dev/null +++ b/feature/preview/src/androidTest/Android.bp @@ -0,0 +1,25 @@ +package { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +android_test { + name: "jetpack-camera-app_feature_preview-android-tests", + team: "trendy_team_camerax", + srcs: ["java/**/*.kt"], + static_libs: [ + "androidx.test.runner", + "junit", + "androidx.test.ext.junit", + "kotlinx_coroutines_test", + "androidx.compose.runtime_runtime", + "androidx.compose.ui_ui-test-junit4", + "androidx.compose.ui_ui-test-manifest", + + ], + instrumentation_for: "jetpack-camera-app_feature_preview", + sdk_version: "34", + test_suites: ["general-tests"], + optimize: { + enabled: false, + }, +} diff --git a/feature/preview/src/androidTest/AndroidManifest.xml b/feature/preview/src/androidTest/AndroidManifest.xml new file mode 100644 index 0000000..bba0f82 --- /dev/null +++ b/feature/preview/src/androidTest/AndroidManifest.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2015 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.google.jetpackcamera.feature.preview.androidtest" > + + <instrumentation + android:name="androidx.test.runner.AndroidJUnitRunner" + android:label="Preview Android Tests" + android:targetPackage="com.google.jetpackcamera.feature.preview" /> + + <application> + <uses-library android:name="android.test.runner" /> + </application> + +</manifest> + + diff --git a/feature/preview/src/androidTest/AndroidTest.xml b/feature/preview/src/androidTest/AndroidTest.xml new file mode 100644 index 0000000..8dcf9fb --- /dev/null +++ b/feature/preview/src/androidTest/AndroidTest.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2017 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<configuration description="Runs Preview Test Cases."> + <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller"> + <option name="cleanup-apks" value="true" /> + <option name="test-file-name" value="jetpack-camera-app_feature_preview-android-tests.apk" /> + </target_preparer> + + <option name="test-tag" value="jetpack-camera-app_feature_preview-android-tests" /> + <test class="com.android.tradefed.testtype.AndroidJUnitTest" > + <option name="package" value="com.google.jetpackcamera.feature.preview.androidtest" /> + <option name="runner" value="androidx.test.runner.AndroidJUnitRunner" /> + </test> +</configuration> + + diff --git a/feature/preview/src/test/java/com/google/jetpackcamera/feature/preview/PreviewViewModelTest.kt b/feature/preview/src/test/java/com/google/jetpackcamera/feature/preview/PreviewViewModelTest.kt index 4e98b0d..0ecd474 100644 --- a/feature/preview/src/test/java/com/google/jetpackcamera/feature/preview/PreviewViewModelTest.kt +++ b/feature/preview/src/test/java/com/google/jetpackcamera/feature/preview/PreviewViewModelTest.kt @@ -53,7 +53,7 @@ class PreviewViewModelTest { @Test fun runCamera() = runTest(StandardTestDispatcher()) { - val surfaceProvider: SurfaceProvider = mock() + val surfaceProvider: SurfaceProvider = mock(SurfaceProvider::class.java) previewViewModel.runCamera(surfaceProvider) advanceUntilIdle() @@ -62,7 +62,7 @@ class PreviewViewModelTest { @Test fun captureImage() = runTest(StandardTestDispatcher()) { - val surfaceProvider: SurfaceProvider = mock() + val surfaceProvider: SurfaceProvider = mock(SurfaceProvider::class.java) previewViewModel.runCamera(surfaceProvider) previewViewModel.captureImage() advanceUntilIdle() @@ -71,8 +71,8 @@ class PreviewViewModelTest { @Test fun captureImageWithUri() = runTest(StandardTestDispatcher()) { - val surfaceProvider: SurfaceProvider = mock() - val contentResolver: ContentResolver = mock() + val surfaceProvider: SurfaceProvider = mock(SurfaceProvider::class.java) + val contentResolver: ContentResolver = mock(ContentResolver::class.java) previewViewModel.runCamera(surfaceProvider) previewViewModel.captureImage(contentResolver, null) {} advanceUntilIdle() @@ -81,7 +81,7 @@ class PreviewViewModelTest { @Test fun startVideoRecording() = runTest(StandardTestDispatcher()) { - previewViewModel.runCamera(mock()) + previewViewModel.runCamera(mock(SurfaceProvider::class.java)) previewViewModel.startVideoRecording() advanceUntilIdle() assertEquals(cameraUseCase.recordingInProgress, true) @@ -89,7 +89,7 @@ class PreviewViewModelTest { @Test fun stopVideoRecording() = runTest(StandardTestDispatcher()) { - previewViewModel.runCamera(mock()) + previewViewModel.runCamera(mock(SurfaceProvider::class.java)) previewViewModel.startVideoRecording() advanceUntilIdle() previewViewModel.stopVideoRecording() @@ -98,7 +98,7 @@ class PreviewViewModelTest { @Test fun setFlash() = runTest(StandardTestDispatcher()) { - previewViewModel.runCamera(mock()) + previewViewModel.runCamera(mock(SurfaceProvider::class.java)) previewViewModel.setFlash(FlashMode.AUTO) advanceUntilIdle() assertEquals( @@ -110,7 +110,7 @@ class PreviewViewModelTest { @Test fun flipCamera() = runTest(StandardTestDispatcher()) { // initial default value should be back - previewViewModel.runCamera(mock()) + previewViewModel.runCamera(mock(SurfaceProvider::class.java)) assertEquals( previewViewModel.previewUiState.value.currentCameraSettings.isFrontCameraFacing, false diff --git a/feature/preview/src/test/java/com/google/jetpackcamera/feature/preview/ScreenFlashTest.kt b/feature/preview/src/test/java/com/google/jetpackcamera/feature/preview/ScreenFlashTest.kt index 2c0e8d8..beeca8e 100644 --- a/feature/preview/src/test/java/com/google/jetpackcamera/feature/preview/ScreenFlashTest.kt +++ b/feature/preview/src/test/java/com/google/jetpackcamera/feature/preview/ScreenFlashTest.kt @@ -51,7 +51,7 @@ class ScreenFlashTest { fun setup() = runTest(testDispatcher) { screenFlash = ScreenFlash(cameraUseCase, testScope) - val surfaceProvider: Preview.SurfaceProvider = Mockito.mock() + val surfaceProvider: Preview.SurfaceProvider = Mockito.mock(Preview.SurfaceProvider::class.java) cameraUseCase.initialize(DEFAULT_CAMERA_APP_SETTINGS) cameraUseCase.runCamera(surfaceProvider, DEFAULT_CAMERA_APP_SETTINGS) } @@ -71,7 +71,7 @@ class ScreenFlashTest { // FlashMode.ON in front facing camera automatically enables screen flash cameraUseCase.setFlashMode(FlashMode.ON, true) - val contentResolver: ContentResolver = Mockito.mock() + val contentResolver: ContentResolver = Mockito.mock(ContentResolver::class.java) cameraUseCase.takePicture(contentResolver, null) advanceUntilIdle() diff --git a/feature/settings/src/androidTest/Android.bp b/feature/settings/src/androidTest/Android.bp new file mode 100644 index 0000000..b0aa3bb --- /dev/null +++ b/feature/settings/src/androidTest/Android.bp @@ -0,0 +1,22 @@ +package { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +android_test { + name: "jetpack-camera-app_feature_settings-tests", + team: "trendy_team_camerax", + srcs: ["java/**/*.kt"], + static_libs: [ + "androidx.test.runner", + "androidx.test.ext.junit", + "kotlinx_coroutines_test", + "androidx.compose.runtime_runtime", + "androidx.compose.ui_ui-test-junit4", + ], + instrumentation_for: "jetpack-camera-app_feature_settings", + sdk_version: "34", + test_suites: ["general-tests"], + optimize: { + enabled: false, + }, +} diff --git a/feature/settings/src/androidTest/AndroidManifest.xml b/feature/settings/src/androidTest/AndroidManifest.xml new file mode 100644 index 0000000..6f4506b --- /dev/null +++ b/feature/settings/src/androidTest/AndroidManifest.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2015 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.google.jetpackcamera.feature.settings.test" > + + <instrumentation + android:name="androidx.test.runner.AndroidJUnitRunner" + android:label="Settings Android Tests" + android:targetPackage="com.google.jetpackcamera.feature.settings" /> + + <application> + <uses-library android:name="android.test.runner" /> + </application> + +</manifest> + + diff --git a/feature/settings/src/androidTest/AndroidTest.xml b/feature/settings/src/androidTest/AndroidTest.xml new file mode 100644 index 0000000..eafe767 --- /dev/null +++ b/feature/settings/src/androidTest/AndroidTest.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2024 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<configuration description="Runs Settings Test Cases."> + <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller"> + <option name="cleanup-apks" value="true" /> + <option name="test-file-name" value="jetpack-camera-app_feature_settings-tests.apk" /> + </target_preparer> + + <option name="test-tag" value="jetpack-camera-app_feature_settings-tests" /> + <test class="com.android.tradefed.testtype.AndroidJUnitTest" > + <option name="package" value="com.google.jetpackcamera.settings.preview.test" /> + <option name="runner" value="androidx.test.runner.AndroidJUnitRunner" /> + </test> +</configuration> + |