[JVM] [SCALA] Spring Injection and cucumber-scala (1.1.3)

216 views
Skip to first unread message

Gerard Maas

unread,
Aug 26, 2013, 1:50:55 PM8/26/13
to cu...@googlegroups.com
Hi,

We are long-time Cucumber/Ruby users/fans for our REST servers. Now we are trying to adopt cucumberJvm (v1.1.3) to test a Java API we are working on. I'm also using the opportunity to introduce Scala in the mix as I'm sure it will appeal to Ruby users as well as the Java veterans around.

I'm in the process of creating up a PoC and currently I'm having issues combining Scala steps and Spring-injected beans. My cucumber.xml setup looks OK and injection works just fine with Java-based step definitions, but my @Autowired vars in the Scala steps with are not being injected up when the tests are run. My runner is correctly annotated with @RunWith(classOf[Cucumber]). 

The steps are found correctly and the tests run, but all @autowired vars remain null. 

Any hints about possible causes? Solutions?

-kr, Gerard. 

Paolo Ambrosio

unread,
Aug 26, 2013, 2:11:04 PM8/26/13
to cu...@googlegroups.com
Spring is not supported by Cucumber-Scala at the moment:
https://github.com/cucumber/cucumber-jvm/issues/469


Paolo

Gerard Maas

unread,
Aug 26, 2013, 2:20:32 PM8/26/13
to cu...@googlegroups.com

Spring is not supported by Cucumber-Scala at the moment:
https://github.com/cucumber/cucumber-jvm/issues/469

Ouch. Thanks. At least it's good to know that we should not keep looking for a problem in our code :-)
I read your comment on the discussion above. "I regret using Spring DI in a Scala project. Sorry, I thought Java DI was used only by people coming from Java background.

Just to add my 2 cents: In our case we would like to use Scala to test a Spring-heavy Java API. It would make a lot of sense for us to have Spring DI working with Scala step defs and logic.

-kr, Gerard.

David Kowis

unread,
Aug 26, 2013, 2:30:17 PM8/26/13
to cu...@googlegroups.com
I've not done a great deal of scala work, but rarely do I see any big
dependency injection frameworks involved in Scala projects.

Scala solves the problem in the core of the language rather than relying
on magical frameworks.

I'd recommend testing with Groovy, so you get the advantages of awesome
syntax. This will cooperate much better with Spring and Big Java
Frameworks in general.

--
David

>
> -kr, Gerard.
>
> --
> -- 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.
> !DSPAM:23,521b9c95162771091512538!

Paolo Ambrosio

unread,
Aug 26, 2013, 4:11:54 PM8/26/13
to cu...@googlegroups.com
On Mon, Aug 26, 2013 at 7:20 PM, Gerard Maas <gerar...@gmail.com> wrote:
>
>> Spring is not supported by Cucumber-Scala at the moment:
>> https://github.com/cucumber/cucumber-jvm/issues/469
>
> Ouch. Thanks. At least it's good to know that we should not keep looking for
> a problem in our code :-)
>
> I read your comment on the discussion above. "I regret using Spring DI in a
> Scala project. Sorry, I thought Java DI was used only by people coming from
> Java background."

In my opinion, but I'm sure others disagree, Spring gets in between of
writing good Scala code (that in my mind means using immutable objects
and functional programming). Perhaps it's not Spring the problem but
using it the wrong way.

I generally agree with what Wille Faler said in this talk last January:

http://skillsmatter.com/podcast/scala/scaling-the-use-of-scala-lessons-learned-from-a-year-of-using-scala-on-a-larger-project

> Just to add my 2 cents: In our case we would like to use Scala to test a
> Spring-heavy Java API. It would make a lot of sense for us to have Spring DI
> working with Scala step defs and logic.

Interesting... why not using Java to test a Java app?

> -kr, Gerard.

There is also a previous thread in the mailing list about making DI
work for other languages:
https://groups.google.com/forum/#!topic/cukes/Qef2OR4xyJg

Gerard Maas

unread,
Aug 26, 2013, 5:01:13 PM8/26/13
to cu...@googlegroups.com
Thanks for the links.


> Just to add my 2 cents: In our case we would like to use Scala to test a
> Spring-heavy Java API. It would make a lot of sense for us to have Spring DI
> working with Scala step defs and logic.

Interesting... why not using Java to test a Java app?

I'm doing my bit of evangelization within the company to get the Scala adoption ball rolling and this is a good, low-risk way of getting it started, I think.

I think I'll hard-wire the Spring dependencies with some Scala objects for the time being. Those are fixed "big external dependencies" anyway.

Thanks for the inputs.

-kr, Gerard.

Reply all
Reply to author
Forward
0 new messages