diff --git a/TestConfigurationSample/app/build.gradle b/TestConfigurationSample/app/build.gradle index 45dd55ca1..ae10f975f 100644 --- a/TestConfigurationSample/app/build.gradle +++ b/TestConfigurationSample/app/build.gradle @@ -1,3 +1,5 @@ +import com.android.build.api.dsl.ManagedVirtualDevice + plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' @@ -48,7 +50,7 @@ android { testOptions { devices { - pixel2api29(com.android.build.api.dsl.ManagedVirtualDevice) { + pixel2api29(ManagedVirtualDevice) { // Use device profiles you typically see in Android Studio device = "Pixel 2" apiLevel = 29 @@ -56,13 +58,13 @@ android { systemImageSource = "aosp" abi = "x86" } - pixel2api26(com.android.build.api.dsl.ManagedVirtualDevice) { + pixel2api26(ManagedVirtualDevice) { device = "Pixel 2" apiLevel = 26 systemImageSource = "aosp" abi = "x86" } - nexus9api29(com.android.build.api.dsl.ManagedVirtualDevice) { + nexus9api29(ManagedVirtualDevice) { device = "Nexus 9" apiLevel = 29 systemImageSource = "aosp" diff --git a/TestConfigurationSample/nav-tests/.gitignore b/TestConfigurationSample/nav-tests/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/TestConfigurationSample/nav-tests/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/TestConfigurationSample/nav-tests/build.gradle b/TestConfigurationSample/nav-tests/build.gradle new file mode 100644 index 000000000..04c5aacfb --- /dev/null +++ b/TestConfigurationSample/nav-tests/build.gradle @@ -0,0 +1,69 @@ +import com.android.build.api.dsl.ManagedVirtualDevice + +plugins { + id 'com.android.test' + id 'org.jetbrains.kotlin.android' +} + +android { + + targetProjectPath ':app' + + compileSdk 31 + + defaultConfig { + applicationId "com.example.android.testing.navtests" + minSdk 21 + targetSdk 31 + versionCode 1 + versionName "1.0" + + testApplicationId "com.example.android.testing.navtests" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } + + testOptions { + devices { + pixel2api29(ManagedVirtualDevice) { + // Use device profiles you typically see in Android Studio + device = "Pixel 2" + apiLevel = 29 + // You can also specify "google" if you require Google Play Services. + systemImageSource = "aosp" + abi = "x86" + } + pixel2api26(ManagedVirtualDevice) { + device = "Pixel 2" + apiLevel = 26 + systemImageSource = "aosp" + abi = "x86" + } + nexus9api29(ManagedVirtualDevice) { + device = "Nexus 9" + apiLevel = 29 + systemImageSource = "aosp" + abi = "x86" + } + } + } +} + +dependencies { + + implementation 'junit:junit:4.13.2' + implementation 'androidx.test.espresso:espresso-core:3.4.0' +} \ No newline at end of file diff --git a/TestConfigurationSample/nav-tests/src/main/AndroidManifest.xml b/TestConfigurationSample/nav-tests/src/main/AndroidManifest.xml new file mode 100644 index 000000000..2792c9faf --- /dev/null +++ b/TestConfigurationSample/nav-tests/src/main/AndroidManifest.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/TestConfigurationSample/nav-tests/src/main/java/com/example/android/testing/navtests/ExampleInstrumentedTest.kt b/TestConfigurationSample/nav-tests/src/main/java/com/example/android/testing/navtests/ExampleInstrumentedTest.kt new file mode 100644 index 000000000..fbc1de9d9 --- /dev/null +++ b/TestConfigurationSample/nav-tests/src/main/java/com/example/android/testing/navtests/ExampleInstrumentedTest.kt @@ -0,0 +1,22 @@ +package com.example.android.testing.navtests + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.runner.AndroidJUnit4 +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.example.android.testing.navtests", appContext.packageName) + } +} \ No newline at end of file diff --git a/TestConfigurationSample/settings.gradle b/TestConfigurationSample/settings.gradle index 701349832..1b575ed23 100644 --- a/TestConfigurationSample/settings.gradle +++ b/TestConfigurationSample/settings.gradle @@ -1,2 +1,3 @@ rootProject.name = "TestConfigurationSample" include ':app' +include ':nav-tests'