Support for Spring

164 views
Skip to first unread message

Duncan McGregor

unread,
Jun 8, 2011, 1:14:26 PM6/8/11
to scalatest-users
I've just had to work out some rudimentary support for @AutoWire -ing
FeatureSpec's from Spring ApplicationContexts.

I've posted the code at http://stackoverflow.com/q/6282471/97777 - it
doesn't make the grade for a framework, but does the trick as a stop-
gap.

Hope it helps someone.

Duncan

Bill Venners

unread,
Jun 8, 2011, 3:08:48 PM6/8/11
to scalate...@googlegroups.com
Hi Duncan,

Thanks for helping out with Spring. I would like to understand what
Spring user's requirements are. Can you possibly post them here, or
email me privately if you think it isn't group-worthy?

Thanks.

Bill

> --
> You received this message because you are subscribed to the Google
> Groups "scalatest-users" group.
> To post to this group, send email to scalate...@googlegroups.com
> To unsubscribe from this group, send email to
> scalatest-use...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/scalatest-users?hl=en
> ScalaTest itself, and documentation, is available here:
> http://www.artima.com/scalatest
>

--
Bill Venners
Artima, Inc.
http://www.artima.com

Duncan McGregor

unread,
Jun 8, 2011, 7:27:42 PM6/8/11
to scalatest-users
/My/ primary requirement is to populate @AutoWire'd fields. I have a
number of integration level tests where I need the whole app wired up
by the ApplicationContext, and then access to various services in that
context to, for example, populate DB tables and check their contents
after tests have run.

Spring will also respect @Transactional annotation on test methods -
which is to say, arrange so that they are run in a transaction, which
is by default rolled-back after test execution to keep the DB clean. I
think you can also apply the annotation on the class so that all test
methods are decorated.

Thats about as much as I know, but there's a large amount of material
at
http://static.springsource.org/spring/docs/3.1.0.M2/spring-framework-reference/html/testing.html

Frankly it does my head in - so I'm trying to keep my exposure as low
as possible, but feel free to ask any more questions and keep up the
good work.

Cheers

Duncan

sami.d...@gmail.com

unread,
Jun 8, 2011, 7:32:59 PM6/8/11
to scalate...@googlegroups.com
Hi,

Here are the important features that Spring-Test provides :

- DI of @Autowired fields on the test case
- Container caching: the container is re-created for each test suite
- Transaction Management (begin / rollback the transaction before / after each test)

regards,
Sami


Duncan

Bill Venners

unread,
Jun 8, 2011, 8:43:35 PM6/8/11
to scalate...@googlegroups.com
Hi Duncan and Sami,

Thanks for the pointers. I'll print that out and try and get my head
around it. If there's someone in the Bay Area doing testing with
Spring who would be willing to walk me through the process, please
email me privately.

Thanks.

Bill

Steven Marcus

unread,
Jun 9, 2011, 7:08:16 AM6/9/11
to scalate...@googlegroups.com
By using scalatest to create JUnit4 compatible tests you can leverage the considerable work that Spring has done to support JUnit4 -- including meeting the 3 requirements that Sami outlines above.

I've found that Spring's SpringJUnit4ClassRunner works well with scalatest.

Thx
S


Duncan McGregor

unread,
Jun 9, 2011, 11:10:01 AM6/9/11
to scalatest-users
On Jun 9, 12:08 pm, Steven Marcus <steven.mar...@gmail.com> wrote:
> I've found that Spring's SpringJUnit4ClassRunner works well with scalatest.
> See http://static.springsource.org/spring/docs/3.0.x/spring-framework-ref...

Am I right in thinking that isn't true for FeatureSpecs though?

Steven Marcus

unread,
Jun 16, 2011, 12:53:59 AM6/16/11
to scalate...@googlegroups.com
I haven't used FeatureSpec yet...

but here is a snippet of an integration test using Spring with an external wiring file:

@RunWith(classOf[SpringJUnit4ClassRunner])
@ContextConfiguration(Array("classpath:/context.xml"))
class RepositorySnapshotIntegrationSuite extends JUnitSuite {

  @Autowired var repoSnapshotService: IRepositorySnapshotService = null

  @Test def simpleTest() { }

}

HTH!
S
Reply all
Reply to author
Forward
0 new messages