Simple Calculator, Unit testing using KOTLIN with

2019-06-11 11:53发布

问题:

I am very new to android developing and recently did my first project. It is only a basic calculator with addition, subtraction, multiplication and division.

I am now trying to do unit testing to test the functions of my calculator but i am receiving this output(shown below). I have no idea what is causing this to happen. Please help

Output:

FunctionsTest.kt:

@RunWith(JUnitPlatform::class)
class FunctionsTest : Spek({

    given("a calculator") {

        on("adding the first number to the second number") {
            val sum = Functions.addFunction(2.0, 3.0)
            it("should return the result of adding the first number to the second number") {
                assertEquals(5, sum)
            }
        }

        on("subtracting the second number from the first number") {
            val sub = Functions.minusFunction(5.0,2.0)
            it("should return the value of subtracting the second number from the first number") {
                assertEquals(3, sub)
            }
        }

        on("Multiplying the first number and the second number") {
            val mul = Functions.multiFunction(5.0,2.0)
            it("should return the value of multiplying the first and second number") {
                assertEquals(10, mul)
            }
        }

        on("Dividing the second number from the first number") {
            val div = Functions.divFunction(9.0,3.0)
            it("should return the value of dividing the second number from the first number") {
                assertEquals(3, div)
            }
        }
    }

})

Gradle Build:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
    applicationId "com.example.zhiwen.calculator"
    minSdkVersion 21
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

androidTestCompile 'com.android.support:support-annotations:25.3.1'
androidTestCompile 'com.android.support.test:runner:0.5'

testCompile"org.jetbrains.spek:spek-api:1.1.2"
testCompile"org.jetbrains.spek:spek-junit-platform-engine:1.1.2"
testCompile"org.junit.platform:junit-platform-runner:1.0.0-M4"




configurations.all {
    resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

dependencies {
    testCompile "com.nhaarman:mockito-kotlin:1.3.0"
}



}
repositories {
maven { url "http://dl.bintray.com/jetbrains/spek" }
mavenCentral()
}