如何解决在 Kotest 单元测试运行时抛出 NoClassDefFoundError
我在运行时得到这个 NoClassDefFoundError
(通过 Intellij 或通过 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)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。