Android Studio 3.3
в build.gradle:
buildscript {
ext.KOTLIN_VERSION = '1.3.21'
ext.ESPRESSO_VERSION = '3.2.0-alpha02'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
В моем приложении / build.gradle:
android {
dataBinding {
enabled = true
}
compileSdkVersion 28
defaultConfig {
applicationId "com.myproject.android"
minSdkVersion 18
targetSdkVersion 28
versionCode 6
versionName "0.0.8"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
androidTest.java.srcDirs += 'src/androidTest/kotlin'
//androidTest.assets.srcDirs += 'src/androidTest/assets'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation('com.crashlytics.sdk.android:crashlytics:2.7.0@aar') { transitive = true; }
implementation 'androidx.appcompat:appcompat:1.1.0-alpha03'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0-alpha03'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha03'
implementation 'com.android.support:design:28.0.0'
implementation 'com.chauthai.swipereveallayout:swipe-reveal-layout:1.4.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.yuyh.json:jsonviewer:1.0.6'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$KOTLIN_VERSION"
implementation project(':common')
androidTestImplementation "androidx.test.espresso:espresso-core:$ESPRESSO_VERSION"
androidTestImplementation "androidx.test.espresso:espresso-intents:$ESPRESSO_VERSION"
androidTestImplementation "androidx.test.espresso:espresso-contrib:$ESPRESSO_VERSION"
androidTestImplementation 'androidx.test:rules:1.1.2-alpha02'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha02'
androidTestImplementation "com.squareup.okhttp3:mockwebserver:3.14.1"
testImplementation 'junit:junit:4.12'
}
Вот тест Эспрессо:
@RunWith(AndroidJUnit4::class)
class TradersActivityTest {
val context = InstrumentationRegistry.getInstrumentation().getContext()
val targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext()
var listItemCount = 0
var checkItemCount = 0;
val mockServer = MockWebServer()
@Rule
@JvmField
var tradersIntentTestRule = IntentsTestRule(TradersActivity::class.java)
@Before
fun setup() {
mockServer.start()
val recyclerView = tradersIntentTestRule.activity.findViewById<View>(R.id.tradersRecyclerView) as RecyclerView
listItemCount = recyclerView.adapter!!.itemCount
checkItemCount = (0..listItemCount - 1).random()
}
Но я получаю ошибку:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:preDebugAndroidTestBuild'.
> Could not resolve all task dependencies for configuration ':app:debugAndroidTestRuntimeClasspath'.
> Could not resolve com.squareup.okhttp3:okhttp:{strictly 3.12.0}.
Required by:
project :app
> Cannot find a version of 'com.squareup.okhttp3:okhttp' that satisfies the version constraints:
Dependency path 'TM:app:unspecified' --> 'com.squareup.okhttp3:mockwebserver:3.14.1' --> 'com.squareup.okhttp3:okhttp:3.14.1'
Constraint path 'TM:app:unspecified' --> 'com.squareup.okhttp3:okhttp:{strictly 3.12.0}' because of the following reason: debugRuntimeClasspath uses version 3.12.0
Constraint path 'TM:app:unspecified' --> 'com.squareup.okhttp3:okhttp:{strictly 3.12.0}' because of the following reason: debugRuntimeClasspath uses version 3.12.0
Constraint path 'TM:app:unspecified' --> 'com.squareup.okhttp3:okhttp:{strictly 3.12.0}' because of the following reason: debugRuntimeClasspath uses version 3.12.0
Constraint path 'TM:app:unspecified' --> 'com.squareup.okhttp3:okhttp:{strictly 3.12.0}' because of the following reason: debugRuntimeClasspath uses version 3.12.0
Constraint path 'TM:app:unspecified' --> 'com.squareup.okhttp3:okhttp:{strictly 3.12.0}' because of the following reason: debugRuntimeClasspath uses version 3.12.0
Constraint path 'TM:app:unspecified' --> 'com.squareup.okhttp3:okhttp:{strictly 3.12.0}' because of the following reason: debugRuntimeClasspath uses version 3.12.0
Constraint path 'TM:app:unspecified' --> 'com.squareup.okhttp3:okhttp:{strictly 3.12.0}' because of the following reason: debugRuntimeClasspath uses version 3.12.0