[英]How to write a test for the Application class in Spring Boot for Kotlin
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
@SpringBootApplication
class GetThingsDoneApplication
fun main(args: Array<String>) {
runApplication<GetThingsDoneApplication>(*args)
}
I am trying to push my test coverage for my project to 100%.
我正在尝试将我的项目的测试覆盖率提高到 100%。 But I don't know how to write a test for main(args: Array<String>)
但我不知道如何为main(args: Array<String>)编写测试
I guess the Test Class and method should look something like this:
我想测试 Class 和方法应该是这个样子:
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
@ContextConfiguration(classes = [GetThingsDoneApplication::class])
class GetThingsDoneApplicationIntegrationTest {
@Test
fun contextLoads() {
main(doSomething())
}
private fun doSomething(): Array<String> {
return arrayOf<String>()
}
}
The question is now, how should my assertThat look like, to have 100% test coverage?
现在的问题是,我的assertThat应该是什么样子才能有 100% 的测试覆盖率?
This works for me
这对我有用
import org.junit.jupiter.api.Test
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ActiveProfiles
import kotlin.test.assertTrue
@SpringBootTest
@ActiveProfiles("test")
internal class SomeAppTest {
@Test
fun contextloads() {
assertTrue { true }
}
}
When you say Failed to load ApplicationContext can you provide the whole stack trace, please?
当你说Failed to load ApplicationContext时,你能提供整个堆栈跟踪吗?
Actually the most effective way to get 100% is to exclude the Application.kt file from the test coverage, like described here IntelliJ - exclude some classes (packages) from test coverage report
实际上,获得 100% 的最有效方法是从测试覆盖率中排除Application.kt文件,如此处所述IntelliJ - exclude some classes (packages) from test coverage report
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.