gpt4 book ai didi

java - Spring Cucumber Serenity 的 Autowiring 步骤

转载 作者:行者123 更新时间:2023-11-28 20:13:28 28 4
gpt4 key购买 nike

我在自动连接某些步骤时失败得很惨。为了说明这一点,我在github上做了一个小示例项目

https://github.com/lpicquet/serenity-cucumber-spring

我正在尝试 Autowiring 步骤,以便我可以在它们之间共享数据,但测试目前失败了。谁能帮忙?

最佳答案

问题是您使用的是不同的 Runner。通常人们使用 SpringRunner.class 来处理创建测试上下文等的能力。

Construct a new SpringRunner and initialize a TestContextManager to provide Spring testing functionality to standard JUnit 4 tests.

要使用不同的运行器和 spring 功能,您可以结合使用 ClassRuleRule

@ClassRule
public static final SpringClassRule SPRING_CLASS_RULE = new SpringClassRule();

@Rule
public final SpringMethodRule springMethodRule = new SpringMethodRule();

SpringClassRule is a custom JUnit TestRule that supports class-level features of the Spring TestContext Framework in standard JUnit tests by means of the TestContextManager and associated support classes and annotations.

In contrast to the SpringJUnit4ClassRunner, Spring's rule-based JUnit support has the advantage that it is independent of any Runner and can therefore be combined with existing alternative runners like JUnit's Parameterized or third-party runners such as the MockitoJUnitRunner.

In order to achieve the same functionality as the SpringJUnit4ClassRunner, however, a SpringClassRule must be combined with a SpringMethodRule, since SpringClassRule only supports the class-level features of the SpringJUnit4ClassRunner.

如果没有这些,就无法在您的依赖类等中 Autowiring 。

我已经通过测试向您的项目添加了一个 PR。

关于java - Spring Cucumber Serenity 的 Autowiring 步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52082246/

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