noclassdeffounderror在运行时对kotest单元测试抛出

smdncfj3  于 2021-08-25  发布在  Java
关注(0)|答案(0)|浏览(259)

我明白了 NoClassDefFoundError 在运行时(通过intellij或via运行测试 gradlew test )
这是我的简单测试(kotlin和kotest的新功能)

class AuthenticationValidatorServiceTest : StringSpec({
    val userRepository = mockk<UserRepository>()
    val userTypeRepository = mockk<UserTypeRepository>()
    val accessTokenRepository  = mockk<AccessTokenRepository>()
    lateinit var service: AuthenticationValidatorService

    beforeTest {
        service = AuthenticationValidatorService(userRepository, userTypeRepository, accessTokenRepository)
    }

    "Should throw ResourceNotFoundException" {
        shouldThrow<ResourceNotFoundException> {
            val userId = UUID.randomUUID()

            every { userRepository.findById(userId) } returns Optional.empty()
            service.validateUser(userId)
        }
    }
})

在我的gradle文件中是否有我错过的设置?我刚刚添加了这个

tasks.withType(Test) {
    useJUnitPlatform()
}

获取这些错误

> Task :test
WARNING: ExecutionInvokerPatcher failed: java.lang.ClassNotFoundException: org.junit.jupiter.engine.descriptor.ClassTestDescriptor

Expected exception lock.http.exception.ResourceNotFoundException but a NoClassDefFoundError was thrown instead.
java.lang.AssertionError: Expected exception lock.http.exception.ResourceNotFoundException but a NoClassDefFoundError was thrown instead.
    at lock.http.service.AuthenticationValidatorServiceTest$1$2.invokeSuspend(AuthenticationValidatorServiceTest.kt:54)
    at lock.http.service.AuthenticationValidatorServiceTest$1$2.invoke(AuthenticationValidatorServiceTest.kt)
    at lock.http.service.AuthenticationValidatorServiceTest$1$2.invoke(AuthenticationValidatorServiceTest.kt)
    at io.kotest.core.spec.style.scopes.StringSpecRootContext$invoke$1.invokeSuspend(StringSpecRootContext.kt:66)
    at io.kotest.core.spec.style.scopes.StringSpecRootContext$invoke$1.invoke(StringSpecRootContext.kt)
    at io.kotest.core.spec.style.scopes.StringSpecRootContext$invoke$1.invoke(StringSpecRootContext.kt)
    at io.kotest.core.internal.ExecutionsKt$executeWithBehaviours$2$1.invokeSuspend(executions.kt:13)
    at io.kotest.core.internal.ExecutionsKt$executeWithBehaviours$2$1.invoke(executions.kt)
    at io.kotest.core.internal.ExecutionsKt$executeWithBehaviours$2$1.invoke(executions.kt)
    at io.kotest.core.internal.ExecutionsKt.wrapTestWithGlobalAssert(executions.kt:39)
    at io.kotest.core.internal.ExecutionsKt.access$wrapTestWithGlobalAssert(executions.kt:1)
    at io.kotest.core.internal.ExecutionsKt$executeWithBehaviours$2.invokeSuspend(executions.kt:12)
    at io.kotest.core.internal.ExecutionsKt$executeWithBehaviours$2.invoke(executions.kt)
    at io.kotest.core.internal.ExecutionsKt$executeWithBehaviours$2.invoke(executions.kt)
    at io.kotest.core.internal.ExecutionsKt$wrapTestWithAssertionModeCheck$2.invokeSuspend(executions.kt:25)
    at io.kotest.core.internal.ExecutionsKt$wrapTestWithAssertionModeCheck$2.invoke(executions.kt)
    at io.kotest.core.internal.ExecutionsKt$wrapTestWithAssertionModeCheck$2.invoke(executions.kt)
    at io.kotest.core.internal.AssertionsCheckKt.executeWithAssertionsCheck(assertionsCheck.kt:25)
    at io.kotest.core.internal.ExecutionsKt.wrapTestWithAssertionModeCheck(executions.kt:24)
    at io.kotest.core.internal.ExecutionsKt.executeWithBehaviours(executions.kt:11)
    at io.kotest.core.internal.TestCaseExecutor$executeInScope$2.invokeSuspend(TestCaseExecutor.kt:268)
    at io.kotest.core.internal.TestCaseExecutor$executeInScope$2.invoke(TestCaseExecutor.kt)
    at io.kotest.core.internal.TestCaseExecutor$executeInScope$2.invoke(TestCaseExecutor.kt)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题