2016-05-23 80 views
1

与Kotlin熟悉了一下我想介绍另一个Android-Java项目,作为仅用于测试的第一步。我决定直接开始Spek运行Spek测试显示错误“空测试套件”

添加以下依赖关系的build.gradle模块的待测试:

testCompile 'junit:junit:4.12' 
testCompile "org.jetbrains.kotlin:kotlin-stdlib:1.0.2" 
testCompile "org.jetbrains.kotlin:kotlin-test-junit:1.0.2" 
testCompile "org.jetbrains.spek:spek:1.0.25" 

除其他我用SimpleTest类git仓库的SPEK-样品:

import org.jetbrains.spek.api.Spek 
import kotlin.test.assertEquals 


class SampleCalculator 
{ 
    fun sum(x: Int, y: Int) = x + y 
    fun subtract(x: Int, y: Int) = x - y 
} 

class SimpleTest : Spek({ 
    describe("a calculator") { 
     val calculator = SampleCalculator() 

     it("should return the result of adding the first number to the second number") { 
      val sum = calculator.sum(2, 4) 
      assertEquals(6, sum) 
     } 

     it("should return the result of subtracting the second number from the first number") { 
      val subtract = calculator.subtract(4, 2) 
      assertEquals(2, subtract) 
     } 
    } 
}) 

代码编译并在Android Studio中,我在类声明旁边显示了一个绿色播放按钮,以运行该类的测试。然而,这样做的结果

Process finished with exit code 1 
Class not found: "com.anfema.ionclient.serialization.SimpleTest"Empty test suite. 

我创建JUnit3和JUnit4测试这些都跑了,没有任何问题。

我是否错过Spek测试的任何其他配置步骤?

回答

1

我的失败是我没有完全/正确地配置Kotlin。

我错过申请的科特林插件,它与这些线完成:

apply plugin: 'kotlin-android' 

buildscript { 
    ext.kotlin_version = '1.0.2' 
    repositories { 
     jcenter() 
    } 

    dependencies { 
     classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 
    } 

这也是有要求的,如果你想在普通JUnit测试使用科特林代码。

相关问题