Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Will Cucumber Java 8 runs outside constructor ? #1233

Closed
mmaryo opened this issue Sep 30, 2017 · 3 comments
Closed

Will Cucumber Java 8 runs outside constructor ? #1233

mmaryo opened this issue Sep 30, 2017 · 3 comments

Comments

@mmaryo
Copy link

mmaryo commented Sep 30, 2017

Hello,

I would like to use the Cucumber Java 8 lambda expressions

Like this : https://cucumber.io/docs/reference/jvm

public class ShoppingStepsDef implements En {
 
    private int budget = 0;
 
    public ShoppingStepsDef() {
	Given("I have (\\d+) in my wallet", (Integer money) -> budget = money);
 
	When("I buy .* with (\\d+)", (Integer price) -> budget -= price);
 
	Then("I should have (\\d+) in my wallet", (Integer finalBudget) -> 
	  assertEquals(budget, finalBudget.intValue()));
    }
}

This syntax is amazing, but runs inside constructor there are problems :

Have you got a plan about that ?

Regards

@mmaryo mmaryo changed the title Will Cucumber Java 8 run outside constructor ? Will Cucumber Java 8 runs outside constructor ? Sep 30, 2017
@mpkorstanje
Copy link
Contributor

mpkorstanje commented Oct 1, 2017

Will Cucumber Java 8 runs outside constructor?

Given the current possibilities of Java 8 no. Perhaps with Java 9 we could use the repl but somebody will have to feel like building it.

we cannot run @before and @after methods of JUnit

Are you certain you do not have these confused with cucumbers @Before and @After? To wit cucumber-junit will only pick up on junits @BeforeClass, @AfterClass and @ClassRule in the runner class. The java8 equivalent of @Before is Before(() -> { // do stuff}); Its various method definitions are located in the parent class of En.

We cannot instantiate Spring context with @Autowired

Please check your implementation against the spring-txn example. If the problem persists please create a minimal complete verifiable example.

Do keep the caveat emptor of How soon will my ticket be fixed? in mind though.

Edit: Yes, the example is written using only annotations but @AutoWired will function the same regardless. To wit using dependency injection through the constructor also works.

@mmaryo
Copy link
Author

mmaryo commented Oct 7, 2017

thanks

@lock
Copy link

lock bot commented Oct 24, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants