Spring Cucumber Serenity 的自动装配步骤
AutoWiring steps with Spring Cucumber Serenity
我在自动连接某些步骤时失败得很惨。
为了说明这一点,我在 github
上做了一个小示例项目
https://github.com/lpicquet/serenity-cucumber-spring
我正在尝试自动装配步骤,以便我可以在它们之间共享数据,但测试目前失败了。有人可以帮忙吗?
问题是您使用的是不同的 Runner。通常人们使用 SpringRunner.class
来处理创建测试上下文等的能力。
Construct a new SpringRunner and initialize a TestContextManager to provide Spring testing functionality to standard JUnit 4 tests.
要使用不同的运行器以及 spring 功能,您可以结合使用 ClassRule
和 Rule
@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.
没有这些,就无法在依赖的 类 等中自动装配
我已经通过测试向你的项目添加了一个 PR。
我在自动连接某些步骤时失败得很惨。 为了说明这一点,我在 github
上做了一个小示例项目https://github.com/lpicquet/serenity-cucumber-spring
我正在尝试自动装配步骤,以便我可以在它们之间共享数据,但测试目前失败了。有人可以帮忙吗?
问题是您使用的是不同的 Runner。通常人们使用 SpringRunner.class
来处理创建测试上下文等的能力。
Construct a new SpringRunner and initialize a TestContextManager to provide Spring testing functionality to standard JUnit 4 tests.
要使用不同的运行器以及 spring 功能,您可以结合使用 ClassRule
和 Rule
@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.
没有这些,就无法在依赖的 类 等中自动装配
我已经通过测试向你的项目添加了一个 PR。