无法运行Koin样本测试

时间:2019-05-26 12:57:11

标签: koin

我想从此网站https://insert-koin.io/docs/2.0/getting-started/junit-test/运行样本测试

class HelloAppTest : AutoCloseKoinTest() {

val model by inject<HelloMessageData>()
val service by inject<HelloService>()

@Before
fun before() {
    startKoin {
        modules(helloModule)
    }
}

@Test
fun tesKoinComponents() {
    val helloApp = HelloApplication()
    helloApp.sayHello()

    assertEquals(service, helloApp.helloService)
    assertEquals("Hey, ${model.message}", service.hello())
}
}

但是它给出了以下错误:

 No tests found for given includes: [HelloAppTest] 
 (filter.includeTestsMatching)

我的gradle文件是这样的:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
buildscript {

dependencies {
    classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.31")
   }
}

plugins {
 kotlin("jvm") version "1.3.21" // duplicate for variable
}

group = "adf"
version = "1.0-SNAPSHOT"

repositories {
  mavenCentral()
 jcenter()
}

dependencies {
 implementation(kotlin("stdlib-jdk8"))

implementation("org.koin:koin-core:2.0.0-rc-1")
testCompile("org.koin:koin-test:2.0.0-rc-1")

}

tasks.withType<KotlinCompile> {
 kotlinOptions.jvmTarget = "1.8"
}

tasks.withType<Test> {
  useJUnitPlatform()
}

如何处理?任何人,请帮助我

这仅用于stackoverflow.com:

Lorem ipsum dolor坐下,奉献己任,sius do eiusmod tempor incididunt ut Labore et dolore magna aliqua。尽量不要抽烟,不要因抽烟而锻炼。 Duis aute irure dolor in reprehenderit in volttable velit esse cillum dolore eu fugiat nulla pariatur。不会出现意外的圣人,反而会在犯规的情况下动手动手。

1 个答案:

答案 0 :(得分:0)

您需要包括以下导入:

testImplementation "junit:junit:4.12"