gpt4 book ai didi

groovy - 如何在 Eclipse 中运行 Spock 测试

转载 作者:行者123 更新时间:2023-12-03 22:44:08 25 4
gpt4 key购买 nike

我尝试在 Eclipse 中运行我的第一个 Spock 测试,但它不起作用。

我在我的 pom.xml 中添加了所有 Maven 依赖项和插件,但是当我使用 jUnit 运行我的测试时,有一个带有此警告消息的弹出窗口:“未找到 jUnit 测试”。

您是否已经看到过此类消息?

为了在 Eclipse 中运行 Spock 测试,必须完成哪些配置?

非常感谢。

最佳答案

它与运行 Junit 测试用例相同。
右键单击该类并作为 4Junit 测试运行器运行。请参阅下面的完整配置和运行 spock 测试。

使用 Eclipse、Gradle、Groovy 运行 Spock 框架:源代码 -
Krzysztof Goralski, blog

-Install Gradle Plugin, check it here

-Install Groovy-Eclipse for Juno or Indigo from Eclipse Marketplace (or maybe Groovy/Grails Tool Suite for Eclipse)

-Install Spock Plugin From Eclipse Marketplace if you want, check it here

-Import Project to Eclipse through Gradle Import

-Add these lines to build.gradle:


apply plugin: ‘groovy’
testCompile ‘org.spockframework:spock-spring:1.0-groovy-2.3’ (for Spring)

this is quite important, version can make some conflicts

-After this *.groovy and *.gradle files will problably looks different, Syntax colour highlightning etc. Remember that you can right click on for eg. build.gradle -> Open with -> Open With Minimalist gradle Editor etc.

-Probably you will need to make additional folder for *.groovy test files Create new *.groovy file, class

-Basic test example, extends Specification from Spock framework and needs specific Annotations when running with Spring

-Now you can run it with JUnit from Eclipse For integration tests you can’t use @RunWith(SpringJUnit4ClassRunner.class), and Context should looks like here @ContextConfiguration(locations = [ “/restTestContext.xml” ]) , not {} braces, but [ ]

-Spock can be used for Mocks too. Something like this: Subscriber subscriber1 = Mock() , subscriber1.isActive() >> true , So, remember >> operator for mocks.

关于groovy - 如何在 Eclipse 中运行 Spock 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10415171/

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