bcarun / cucumber-samples Goto Github PK
View Code? Open in Web Editor NEWSamples to show Behavior Driven Development using Cucumber
License: Apache License 2.0
Samples to show Behavior Driven Development using Cucumber
License: Apache License 2.0
Thanks for providing sample code. This works fine as "mvn test".
Can this be run as an application? i.e.
java -jar target\hello-springboot-cucumber-1.0.0.jar
(it starts as a normal spring-boot application with embedded tomcat, and doesn't run the test)
Great example of sharing test context between steps (sharing-state-between-stepdefs).
I'm using this example, which works great as long as you are within the stepdefs class, but when I pass the TestContext
from the @ScenarioScope
bean to another spring component, and try to access the TestContext
, I'm getting an error (Cucumber version 7.2.3):
org.springframework.beans.factory.support.ScopeNotActiveException: Error creating bean with name 'scopedTarget.myTestContext': Scope 'cucumber-glue' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: Scenario scoped beans can only be created while Cucumber is executing a scenario
So let's say I have the following @ScenarioScope
class:
@ScenarioScope
@Component
public class MyTestContext {
public TestContext getTestContext() {
return TestContext.CONTEXT;
}
}
An Integration test with the glue configuration:
/**
* @ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.mycompany.e2e.cucumber")
* @ConfigurationParameter(key = FEATURES_PROPERTY_NAME, value = "src/test/resources/com/mycompany/e2e/cucumber")
*/
@Suite
@SuiteDisplayName("e2e test")
@SelectClasspathResource("com/mycompany/e2e/cucumber")
@ConfigurationParameter(
key = PLUGIN_PROPERTY_NAME,
value="pretty, html:target/cucumber-reports/myproject-e2e.html, json:target/cucumber-reports/myproject-e2e.json")
public class MyIntegrationTest {
}
My stepdefs class:
@Slf4j
@RequiredArgsConstructor
public class MyStepDefs {
private final MyTestContext testContext;
// a class which contains some methods to do assertions; to some of these methods I pass the testContext;
// accessing testContext in these methods fail with the aforementioned exception.
private final MyStepDefAsserter asserter;
private final TestConfiguration testConfiguration;
@Given("a message with")
public void givenAMessageWith(Input myInput) {
testContext.getTestContext().set("myJsonMessage", myInput.toString());
}
@Then("I expect a json message")
public void thenIExcpectAJsonMessage() {
asserter.assertMyJsonMessage(testContext);
}
}
And the MyStepDefAsserter
class:
@Slf4j
@Component
@RequiredArgsConstructor
public class MyStepDefAsserter {
private final MyStepDefsHelper helper;
private final TestConfiguration testConfiguration;
public void assertMyJsonMessage(MyTestContext testContext) {
final var myJsonMessage = testContext.getTestContext().get("myJsonMessage"); // this is where it fails with aforementioned exception
// assertions here
}
}
Any idea why this fails? Am I missing some configuration here?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.