gpt4 book ai didi

java - Spek 测试未在 Maven Java 项目中运行

转载 作者:太空宇宙 更新时间:2023-11-04 10:07:47 25 4
gpt4 key购买 nike

我有一个现有的 Java 项目,我希望在其中引入一些规范测试(在 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-plugin 配置)

       <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 文件)

最佳答案

我知道您说过您尝试过不同的版本,但请尝试 Surefire 2.19 和 Junit-platform 1.1.0-M2。

不久前我也遇到了同样的问题,这些对我有用。

关于java - Spek 测试未在 Maven Java 项目中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52735929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com