1

我想从这个站点运行示例测试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 sit amet,consectetur adipiscing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua。Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat。Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur。Exceptioneur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est labourum。

4

1 回答 1

0

您需要包括以下导入:

testImplementation "junit:junit:4.12"
于 2019-07-03T16:29:24.280 回答