initial idea to login in during tests

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2021-07-23 16:44:33 +02:00 committed by Tim Krüger
parent aaa9567c19
commit 5ad48b3757
No known key found for this signature in database
GPG Key ID: FECE3A7222C52A4E
3 changed files with 69 additions and 2 deletions

View File

@ -159,6 +159,7 @@ ext {
retrofit2Version = "2.9.0" retrofit2Version = "2.9.0"
workVersion = "2.6.0" workVersion = "2.6.0"
markwonVersion = "4.6.2" markwonVersion = "4.6.2"
espressoVersion = "3.4.0"
} }
configurations.all { configurations.all {
@ -296,6 +297,13 @@ dependencies {
testImplementation "org.powermock:powermock-module-junit4:${powermockVersion}" testImplementation "org.powermock:powermock-module-junit4:${powermockVersion}"
testImplementation "org.powermock:powermock-api-mockito2:${powermockVersion}" testImplementation "org.powermock:powermock-api-mockito2:${powermockVersion}"
// Espresso core
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-web:$espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-accessibility:$espressoVersion"
androidTestImplementation('com.android.support.test.espresso:espresso-intents:3.0.2')
androidTestImplementation ('androidx.test.espresso:espresso-core:3.4.0', { androidTestImplementation ('androidx.test.espresso:espresso-core:3.4.0', {
exclude group: 'com.android.support', module: 'support-annotations' exclude group: 'com.android.support', module: 'support-annotations'
}) })

View File

@ -0,0 +1,59 @@
package com.nextcloud.talk.activities
import android.util.Log
import androidx.test.espresso.intent.rule.IntentsTestRule
import com.nextcloud.talk.models.database.UserEntity
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import junit.framework.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
class MainActivityTest {
@get:Rule
val activityRule: IntentsTestRule<MainActivity> = IntentsTestRule(
MainActivity::class.java,
true,
false
)
@Test
fun login() {
val sut = activityRule.launchActivity(null)
sut.userUtils.createOrUpdateUser(
"test",
"test",
"http://10.0.2.2/nc",
"test",
null,
true,
"test",
null,
null,
null,
null
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ userEntity: UserEntity? -> Log.i("test", "stored: " + userEntity.toString()) },
{ throwable: Throwable? -> Log.e("test", "throwable") },
{ Log.d("test", "complete") }
)
try {
Thread.sleep(2000)
} catch (e: InterruptedException) {
e.printStackTrace()
}
sut.runOnUiThread { sut.resetConversationsList() }
assertTrue(sut.userUtils.getIfUserWithUsernameAndServer("test", "http://10.0.2.2/nc"))
try {
} catch (e: InterruptedException) {
e.printStackTrace()
}
}
}

View File

@ -268,7 +268,7 @@ public class UserUtils {
} }
return dataStore.upsert(user) return dataStore.upsert(user)
.toObservable() .toObservable()
.subscribeOn(Schedulers.io()); .subscribeOn(Schedulers.io());
} }
} }