jbehave-junit-runner icon indicating copy to clipboard operation
jbehave-junit-runner copied to clipboard

Create an example on how to inject members into a test using spring

Open britter opened this issue 11 years ago • 4 comments
trafficstars

We had quite a few requests on how to use the jbehave-junit-runner together with spring. The problem is, that both, our library and spring test provide a JUnitRunner and only one runner can be declared per test.

We should document a way to inject members into a jbehave junit test using spring. The easiest way would probably be, to create an ApplicationContext in the @Before hock by hand, get an AutowireCapableFactoryBean from there and then call autowireBean(Object)passing in the this reference (see also: http://stackoverflow.com/questions/3813588/how-to-inject-dependencies-into-a-self-instantiated-object-in-spring).

britter avatar Jun 28 '14 17:06 britter

@britter Does it make sense to move the examples to another project (#54) within the same repository (similar to https://github.com/codecentric/zucchini) before #62?

visusnet avatar Jun 28 '14 19:06 visusnet

@visusnet makes sense to me!

britter avatar Jun 29 '14 13:06 britter

What's the state of the art now? I have an exploratory project that uses SpringJUnit4ClassRunner to run its stories (see example, but my IDE doesn't show the steps beautifully in its test result navigator. So I want to use jbehave-junit-runner, which has worked beautifully for me with statically configured tests. But I can't use it without Spring autowiring.

sheldonh avatar Dec 11 '14 12:12 sheldonh

Any news about this? or document about the best practices to put this in place?

I am currently trying it and it's not very strait forward.

The @Rule from Spring sounds promising but I couldn't make it work yet

cfontes avatar Sep 30 '15 18:09 cfontes