Re: [Cucumber] cucumber-weld problem

117 views
Skip to first unread message

aslak hellesoy

unread,
May 17, 2013, 10:41:15 AM5/17/13
to Cucumber Users



On Fri, May 17, 2013 at 9:31 AM, Marvin Schramm <marvin....@gmail.com> wrote:

It seems that if i activate cucumber-weld (with org.jboss.weld.se), this happens:

Please paste the entire class, not just the methods.

Aslak 

@Before
public void before() {
   ExampleClass ec = new ExampleClass();
}

@Given("^someGiven")
public void given() {
   ec.bar();<----throws nullpointer with cucumber-weld activated
}
@When("^someWhen")
public void when() {
   ec.bar();<----throws nullpointer with cucumber-weld activated
}
@Then("^someGiven")
public void then() {
   ec.bar();<----throws nullpointer with cucumber-weld activated
}

Looks like that every method is executed independently and a scenario can't hold a state in this way. As soon as i remove "org.jboss.weld.se" from my pom.xml CDI doesnt work anymore (as expected) but the Nullpointers are gone. Tested with (1.1.2 and 1.1.3)

I checked out this code also and confirmed the issue too "https://github.com/GallifreyanCode/cucumber-jvm-examples/tree/master/cucumber-example-cdi" (cucumber 1.0.0.RC20)

Aslak Hellesøy said this is not a bug, but that im doing something wrong, did anyone encounter this issue? Or can help me to solve it?

Greetings


--
-- Rules --
 
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.
 
You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cu...@googlegroups.com. To unsubscribe from this group, send email to cukes+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Marvin Schramm

unread,
May 17, 2013, 10:54:35 AM5/17/13
to cu...@googlegroups.com

Sorry, here is a gist with the corresponding files.




On Friday, May 17, 2013 4:31:20 PM UTC+2, Marvin Schramm wrote:

It seems that if i activate cucumber-weld (with org.jboss.weld.se), this happens:

@Before
public void before() {
   ExampleClass ec = new ExampleClass();
}

@Given("^someGiven")
public void given() {
   ec.bar();<----throws nullpointer with cucumber-weld activated
}
@When("^someWhen")
public void when() {
   ec.bar();<----throws nullpointer with cucumber-weld activated
}
@Then("^someGiven")
public void then() {
   ec.bar();<----throws nullpointer with cucumber-weld activated
}

aslak hellesoy

unread,
May 17, 2013, 11:04:26 AM5/17/13
to Cucumber Users
Please read up on rule 2 at the bottom of the message.


On Fri, May 17, 2013 at 9:54 AM, Marvin Schramm <marvin....@gmail.com> wrote:

Sorry, here is a gist with the corresponding files.




Ok, so something is null. What's null?
 

On Friday, May 17, 2013 4:31:20 PM UTC+2, Marvin Schramm wrote:

It seems that if i activate cucumber-weld (with org.jboss.weld.se), this happens:


@Before
public void before() {
   ExampleClass ec = new ExampleClass();
}

@Given("^someGiven")
public void given() {
   ec.bar();<----throws nullpointer with cucumber-weld activated
}
@When("^someWhen")
public void when() {
   ec.bar();<----throws nullpointer with cucumber-weld activated
}
@Then("^someGiven")
public void then() {
   ec.bar();<----throws nullpointer with cucumber-weld activated
}

Looks like that every method is executed independently and a scenario can't hold a state in this way. As soon as i remove "org.jboss.weld.se" from my pom.xml CDI doesnt work anymore (as expected) but the Nullpointers are gone. Tested with (1.1.2 and 1.1.3)

I checked out this code also and confirmed the issue too "https://github.com/GallifreyanCode/cucumber-jvm-examples/tree/master/cucumber-example-cdi" (cucumber 1.0.0.RC20)

Aslak Hellesøy said this is not a bug,

I didn't say that - I said *I don't think you have found a bug*. (https://github.com/cucumber/cucumber-jvm/issues/521)
 
but that im doing something wrong, did anyone encounter this issue? Or can help me to solve it?

Greetings


Marvin Schramm

unread,
May 17, 2013, 11:13:33 AM5/17/13
to cu...@googlegroups.com


On Friday, May 17, 2013 5:04:26 PM UTC+2, Aslak Hellesøy wrote:
Please read up on rule 2 at the bottom of the message.

OK
 
On Fri, May 17, 2013 at 9:54 AM, Marvin Schramm <marvin....@gmail.com> wrote:

Sorry, here is a gist with the corresponding files.




Ok, so something is null. What's null?
 
Well the DataAccessObject is null. It seems that the StepClass is created for every Step new ( I created a constructor in the StepDefs.Class to confirm that).  

aslak hellesoy

unread,
May 17, 2013, 12:48:31 PM5/17/13
to Cucumber Users
On Fri, May 17, 2013 at 10:13 AM, Marvin Schramm <marvin....@gmail.com> wrote:


On Friday, May 17, 2013 5:04:26 PM UTC+2, Aslak Hellesøy wrote:
Please read up on rule 2 at the bottom of the message.

OK
 
On Fri, May 17, 2013 at 9:54 AM, Marvin Schramm <marvin....@gmail.com> wrote:

Sorry, here is a gist with the corresponding files.




Ok, so something is null. What's null?
 
Well the DataAccessObject is null. It seems that the StepClass is created for every Step new ( I created a constructor in the StepDefs.Class to confirm that).  

If that was the case, this change would have broken the build:


Each stepdef class instantiated once for every *scenario* and then reused for every *step*.
How did you conclude that you get a new instance for every step?

Aslak

Marvin Schramm

unread,
May 17, 2013, 1:11:01 PM5/17/13
to cu...@googlegroups.com


On Friday, May 17, 2013 6:48:31 PM UTC+2, Aslak Hellesøy wrote:



On Fri, May 17, 2013 at 10:13 AM, Marvin Schramm <marvin....@gmail.com> wrote:


On Friday, May 17, 2013 5:04:26 PM UTC+2, Aslak Hellesøy wrote:
Please read up on rule 2 at the bottom of the message.

OK
 
On Fri, May 17, 2013 at 9:54 AM, Marvin Schramm <marvin....@gmail.com> wrote:

Sorry, here is a gist with the corresponding files.




Ok, so something is null. What's null?
 
Well the DataAccessObject is null. It seems that the StepClass is created for every Step new ( I created a constructor in the StepDefs.Class to confirm that).  

If that was the case, this change would have broken the build:

 
Each stepdef class instantiated once for every *scenario* and then reused for every *step*.
How did you conclude that you get a new instance for every step?

Yeah I know that the stepdef class should be instantiated once. (this is the case when i remove the weld-se dependency)
I created a constructor in the stepdef class, and when i run the test it gets called several times. 
here a gist with my Cucumber JUnit Log (with and without weld-es)


I looked at your commit and this solved my problem. (i added @javax.inject.Singleton) to the stepdef class.
Did Weld create a pool >1 for my StepDef class? Can you clarify that for me?


Thank your for taking the time to help me with that issue.

Marvin
Reply all
Reply to author
Forward
0 new messages