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%. But I don't know how to write a test for main(args: Array<String>)
I guess the Test Class and method should look something like this:
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?
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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.