Skip to content

Added Roboelectric and AndroidX Test suit #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 26, 2023
Merged
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
13 changes: 13 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ apply plugin: "androidx.navigation.safeargs.kotlin"
android {
compileSdkVersion rootProject.compileSdkVersion

/**
* Allows to access Android Resources in your unit tests, including AndroidManifest file.
* This will resolve "no such as manifest file: " warning.
*/
testOptions.unitTests {
includeAndroidResources = true
}

defaultConfig {
applicationId "com.example.android.architecture.blueprints.reactive"
minSdkVersion rootProject.minSdkVersion
Expand Down Expand Up @@ -54,6 +62,11 @@ dependencies {
testImplementation "junit:junit:$junitVersion"
testImplementation "com.google.truth:truth:1.1.2"

// AndroidX Test - JVM testing
testImplementation "androidx.test.ext:junit-ktx:$androidXTestExtKotlinRunnerVersion"
testImplementation "androidx.test:core-ktx:$androidXTestCoreVersion"
testImplementation "org.robolectric:robolectric:$robolectricVersion"

// AndroidX Test - Instrumented testing
androidTestImplementation "androidx.test.ext:junit:$androidXTestExtKotlinRunnerVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package com.example.android.architecture.blueprints.todoapp.statistics
import com.example.android.architecture.blueprints.todoapp.data.Task
import com.google.common.truth.Truth
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4


@RunWith(JUnit4::class)
internal class StatisticsUtilsTest {


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.android.architecture.blueprints.todoapp.tasks

import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith


@RunWith(AndroidJUnit4::class)
internal class TasksViewModelTest {

@Test
fun addNewTask_setNewTask() {

// Assign a ViewModel
val tasksViewModel = TasksViewModel(ApplicationProvider.getApplicationContext())

// Assert adding a new Task
tasksViewModel.addNewTask()

// Act new Task is added
// TODO: Test live data.
}
}
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ buildscript {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
Expand Down Expand Up @@ -46,6 +47,7 @@ ext {
recyclerViewVersion = '1.2.1'
roomVersion = '2.3.0'
rulesVersion = '1.0.1'
robolectricVersion = '4.10.3'
swipeRefreshLayoutVersion = '1.1.0'
timberVersion = '4.7.1'
}