【问题标题】:Can not run sample test Koin无法运行示例测试 Koin
【发布时间】:2019-07-04 00:29:24
【问题描述】:

我想从这个站点运行示例测试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 laborum。

【问题讨论】:

    标签: koin


    【解决方案1】:

    您需要包含以下导入:

    testImplementation "junit:junit:4.12"
    

    【讨论】:

    • 如果对您有帮助,请将其标记为正确。否则请告诉我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多