Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ android {
versionName "1.0-alpha1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation" : "$projectDir/schemas".toString(),
Expand Down Expand Up @@ -69,7 +68,9 @@ dependencies {
api 'androidx.cardview:cardview:1.0.0'
//android app architecture components
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-ktx:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
kapt "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
Expand Down Expand Up @@ -110,12 +111,15 @@ dependencies {
// Optional -- Robolectric environment
testImplementation 'androidx.test:core:1.2.0'
// Optional -- Mockito framework
testImplementation 'org.mockito:mockito-core:3.1.0'
// testImplementation 'org.mockito:mockito-inline:3.1.0'
testImplementation "org.mockito:mockito-core:3.3.0"
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
testImplementation("com.squareup.okhttp3:mockwebserver:4.4.0")
// AndroidJUnitRunner and JUnit Rules
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'

testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.5'
}

Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.cn29.aac.datasource.auth.db

import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.lifecycle.LiveData
import androidx.room.Room
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import androidx.test.platform.app.InstrumentationRegistry
import com.cn29.aac.repo.user.LoginBean
import com.cn29.aac.utils.LiveDataTestUtil
import kotlinx.coroutines.runBlocking
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Before
Expand All @@ -20,7 +19,7 @@ internal class AuthDaoTest {
val instantTaskExecutorRule = InstantTaskExecutorRule()
private lateinit var authDb: AuthDb
private lateinit var authDao: AuthDao
private lateinit var getLoginLiveData: LiveData<LoginBean>
private lateinit var loginBeanFromDao: LoginBean

@Before
fun setUp() {
Expand All @@ -35,25 +34,24 @@ internal class AuthDaoTest {
}

@Test
fun should_insert_login_and_fetch() {
fun should_insert_login_and_fetch() = runBlocking {
val loginBean = generateDummyLoginBean()
givenLoginBeanInserted(loginBean)
whenGetLoginByEmail(email = "[email protected]")
thenFetchedLoginBeanShouldBe(expect = loginBean,
actual = LiveDataTestUtil.getValue(
getLoginLiveData))
actual = loginBeanFromDao)
}

private fun thenFetchedLoginBeanShouldBe(expect: LoginBean,
actual: LoginBean) {
assertEquals(expect, actual)
}

private fun whenGetLoginByEmail(email: String) {
getLoginLiveData = authDao.getLogin(email)
private suspend fun whenGetLoginByEmail(email: String) {
loginBeanFromDao = authDao.getLogin(email)
}

private fun givenLoginBeanInserted(loginBean: LoginBean) {
private suspend fun givenLoginBeanInserted(loginBean: LoginBean) {
authDao.insert(loginBean)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.cn29.aac.repo.github.Contributor
import com.cn29.aac.repo.github.Repo
import com.cn29.aac.repo.github.RepoSearchResult
import com.cn29.aac.utils.LiveDataTestUtil
import kotlinx.coroutines.runBlocking
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Before
Expand All @@ -19,8 +20,8 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4ClassRunner::class)
internal class RepoDaoTest {
private lateinit var loadContributors: LiveData<List<Contributor>>
private lateinit var loadRepoList: LiveData<List<Repo>>
private lateinit var loadRepo: LiveData<Repo>
private lateinit var loadRepoList: List<Repo>
private lateinit var loadRepo: Repo

@get:Rule
val instantTaskExecutorRule = InstantTaskExecutorRule()
Expand All @@ -41,23 +42,23 @@ internal class RepoDaoTest {
}

@Test
fun should_insert_1_repo() {
fun should_insert_1_repo() = runBlocking {
val repo = generateDummyRepo()
givenRepoInserted(*repo.toTypedArray())
whenLoadRepositories("charlesng0209")
thenRepoListSizeShouldBe(1)
thenRepoShouldBe(repo[0],
LiveDataTestUtil.getValue(loadRepoList)[0])
loadRepoList[0])
}

@Test
fun should_insert_1_repo_empty_desc() {
fun should_insert_1_repo_empty_desc() = runBlocking {
val repo = generateDummyRepo(description = null)
givenRepoInserted(*repo.toTypedArray())
whenLoadRepositories("charlesng0209")
thenRepoListSizeShouldBe(1)
thenRepoShouldBe(repo[0],
LiveDataTestUtil.getValue(loadRepoList)[0])
loadRepoList[0])
}

@Test
Expand All @@ -71,7 +72,7 @@ internal class RepoDaoTest {
}

@Test
fun should_insert_repos_list() {
fun should_insert_repos_list() = runBlocking {
val repo = generateDummyRepo(3)
givenRepoInserted(*repo.toTypedArray())
whenLoadRepositories("charlesng0209")
Expand All @@ -80,12 +81,12 @@ internal class RepoDaoTest {


@Test
fun should_load_repo_with_login_and_name() {
fun should_load_repo_with_login_and_name() = runBlocking {
val repo = generateDummyRepo(1)
givenRepoInserted(*repo.toTypedArray())
whenLoad(login = "charlesng0209", name = "Testing1")
thenRepoShouldBe(expect = repo[0],
actual = LiveDataTestUtil.getValue(loadRepo))
actual = loadRepo)
}

@Test
Expand All @@ -95,14 +96,14 @@ internal class RepoDaoTest {
}

@Test
fun should_return_2_repos() {
fun should_return_2_repos() = runBlocking {
val repos = generateDummyRepo(3)
givenRepoInserted(*repos.toTypedArray())
whenRepoLoadById(1, 2, 3)
thenRepoListSizeShouldBe(3)
}

private fun whenRepoLoadById(vararg repoIds: Int) {
private suspend fun whenRepoLoadById(vararg repoIds: Int) {
loadRepoList = repoDao.loadById(repoIds.toList())
}

Expand All @@ -116,8 +117,8 @@ internal class RepoDaoTest {
totalCount = 4,
next = 3)

private fun whenLoad(login: String,
name: String) {
private suspend fun whenLoad(login: String,
name: String) {
loadRepo = repoDao.load(login, name)
}

Expand All @@ -143,10 +144,10 @@ internal class RepoDaoTest {
}

private fun thenRepoListSizeShouldBe(size: Int) {
assertEquals(size, LiveDataTestUtil.getValue(loadRepoList).size)
assertEquals(size, loadRepoList.size)
}

private fun whenLoadRepositories(owner: String) {
private suspend fun whenLoadRepositories(owner: String) {
this.loadRepoList = repoDao.loadRepositories(owner = owner)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class FeedActivityTest {
FeedActivity::class.java)

@Test
fun should_open_feed_page() {
fun should_open_page() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.cn29.aac.ui.feedentrydetail

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@LargeTest
internal class FeedEntryDetailActivityTest {
@get:Rule
var activityRule: ActivityTestRule<FeedEntryDetailActivity> = ActivityTestRule(
FeedEntryDetailActivity::class.java)

@Test
fun should_open_page() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.cn29.aac.ui.location

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@LargeTest
internal class LocationActivityTest {

@get:Rule
var activityRule: ActivityTestRule<LocationActivity> = ActivityTestRule(
LocationActivity::class.java)

@Test
fun should_open_page() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.cn29.aac.ui.login

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@LargeTest
internal class LoginActivityTest {

@get:Rule
var activityRule: ActivityTestRule<LoginActivity> = ActivityTestRule(
LoginActivity::class.java)

@Test
fun should_open_page() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.cn29.aac.ui.main

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@LargeTest
internal class AppArchNavigationDrawerTest {

@get:Rule
var activityRule: ActivityTestRule<AppArchNavigationDrawer> = ActivityTestRule(
AppArchNavigationDrawer::class.java)

@Test
fun should_open_page() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.cn29.aac.ui.masterdetail

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@LargeTest
internal class SimpleDetailActivityTest {
@get:Rule
var activityRule: ActivityTestRule<SimpleDetailActivity> = ActivityTestRule(
SimpleDetailActivity::class.java)

@Test
fun should_open_page() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.cn29.aac.ui.masterdetail

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@LargeTest
internal class SimpleListActivityTest {

@get:Rule
var activityRule: ActivityTestRule<SimpleListActivity> = ActivityTestRule(
SimpleListActivity::class.java)

@Test
fun should_open_page() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.cn29.aac.ui.setting

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@LargeTest
internal class SettingsActivityTest {
@get:Rule
var activityRule: ActivityTestRule<SettingsActivity> = ActivityTestRule(
SettingsActivity::class.java)

@Test
fun should_open_page() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.cn29.aac.ui.shopping

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@LargeTest
internal class ArtistDetailActivityTest {
@get:Rule
var activityRule: ActivityTestRule<ArtistDetailActivity> = ActivityTestRule(
ArtistDetailActivity::class.java)

@Test
fun should_open_page() {

}
}
Loading