Kotlin - 运行集成测试,错误`fun main已定义`

时间:2015-11-28 08:51:54

标签: maven spring-boot integration-testing kotlin

我已经为Web应用程序编写了集成测试,但我不知道如何运行此测试。执行mvn test

时,Maven构建失败并出现以下错误
[INFO] Compiling Kotlin sources from [src/main/kotlin]
[INFO] Classpath: <...>
[INFO] Classes directory is <...>\target\classes
[INFO] Module name is demo
[ERROR] <...>\src\main\kotlin\demo\Application.kt: (9, 1) 'public fun main(args: kotlin.Array<kotlin.String>): kotlin.Unit' is already defined in demo
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

这是我的主要课程(Application.kt)

package demo

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication

@SpringBootApplication
open class Application

fun main(args: Array<String>) {
    SpringApplication.run(Application::class.java, *args)
}

这是我的测试类的一部分

package demo

import org.junit.runner.RunWith
import org.springframework.boot.test.SpringApplicationConfiguration
import org.springframework.boot.test.WebIntegrationTest
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner
import demo.Application
import demo.model.City
import demo.repository.CityRepository

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebIntegrationTest({"server.port=8080"})
class CityControllerTest {
    @Autowired
    private var cityRepository: CityRepository?
    private val restTemplate: RestTemplate = TestRestTemplate()
    // ...
}

执行mvn clean test时没有这样的错误。所以我认为Kotlin对之前编译的类很害怕。虽然我很不确定......

运行集成测试的正确方法是什么?

1 个答案:

答案 0 :(得分:2)

这是一个错误(https://youtrack.jetbrains.com/issue/KT-10051)。已经修复,修复将很快交付