Skip to content

Commit

Permalink
add first test
Browse files Browse the repository at this point in the history
  • Loading branch information
solygambas committed Apr 21, 2022
1 parent 2a8c391 commit 95b2d51
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions 25-to-do-notes/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ dependencies {

// Dependencies for local unit tests
testImplementation "junit:junit:$junitVersion"
testImplementation "org.hamcrest:hamcrest-all:$hamcrestVersion"

// AndroidX Test - Instrumented testing
androidTestImplementation "androidx.test.ext:junit:$androidXTestExtKotlinRunnerVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
assertEquals(3, 1 + 1)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.android.architecture.blueprints.todoapp.statistics

import com.example.android.architecture.blueprints.todoapp.data.Task
import org.hamcrest.Matchers.`is`
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Test

class StatisticsUtilsTest {

// Give meaningful names: subjectUnderTest_actionOrInput_resultState
@Test
fun getActiveAndCompleteStats_noCompleted_returnsHundredZero() {
// Arrange - Given: create an active task
val tasks = listOf<Task>(
Task("title", "description", isCompleted = false)
)
// Act - When: call the function
val result = getActiveAndCompletedStats(tasks)

// Assert - Then: check the result
/*assertEquals(result.completedTasksPercent, 0f)
assertEquals(result.activeTasksPercent, 100f)*/

// use hamcrest
assertThat(result.activeTasksPercent, `is`(100f))
assertThat(result.completedTasksPercent, `is`(0f))
}

}
1 change: 1 addition & 0 deletions 25-to-do-notes/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ ext {
cardVersion = '1.0.0'
espressoVersion = '3.4.0'
fragmentKtxVersion = '1.4.0'
hamcrestVersion = '1.3'
junitVersion = '4.13.2'
materialVersion = '1.4.0'
recyclerViewVersion = '1.2.1'
Expand Down

0 comments on commit 95b2d51

Please sign in to comment.