我有一个现有的 Java 项目,我希望在其中介绍一些 Spec 测试(在 kotlin ofc 中)
class CalcSpec: Spek({
given("A calculator") {
val calculator = Calculator()
on("Adding 3 and 5") {
val result = calculator.sum(3, 5)
it("Produces 8") {
org.junit.jupiter.api.Assertions.assertEquals(8, result)
}
}
}
})
我添加了 spek 依赖项
<dependency>
<groupId>org.jetbrains.spek</groupId>
<artifactId>spek-api</artifactId>
<version>1.1.5</version>
<type>pom</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.spek</groupId>
<artifactId>spek-junit-platform-engine</artifactId>
<version>1.1.5</version>
<type>pom</type>
<scope>test</scope>
</dependency>
并按照此处的描述配置了 kotlin-maven-plugin 和 maven-compiler-plugin https://kotlinlang.org/docs/reference/using-maven.html#compiling-kotlin-and-java-sources
(省略了 maven-compiler -插件配置来自问题)
<build>
<plugins>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>1.0.6</version>
<executions>
<execution>
<id>test-compile</id>
<phase>process-test-sources</phase>
<goals> <goal>test-compile</goal> </goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<useManifestOnlyJar>false</useManifestOnlyJar>
<includes>
<include>**/*Spec.*</include>
</includes>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</plugin>
...
</plugins>
</build>
我尝试过不同版本的 kotlin、spek 和 surefire 插件,但直到现在都没有运气。
每次我尝试运行测试时,都没有执行任何 Spek 测试,即使它们在target/test-classes
. (对于 CalcSpec,生成了 5 个 .class 文件)