Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Spring in Action 5th Edition... testing with Spring Beans  RSS feed

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the quickest and easiest way to create a Spring context to use in junit test classes?

Are there strategies for  this covered in the book?

Thanks! :-)

YoungJules
 
author
Posts: 396
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I don't cover testing explicitly in the book, but I do have a few tests sprinkled around in the book and in the sample code that accompanies the book. In short, using Spring Boot you just annotate your test class with @SpringBootTest and @RunWith(SpringRunner.class) and then @Autowire any beans you want to test into the test class itself.

To get you started, if you create a new project using the Initializr (start.spring.io), you will get a *very* simple test that proves that the application context loads cleanly. Looks a little like this:



You would, of course, write more tests (using this as a template) to assert application/component behavior.

Julian Isaac wrote:What's the quickest and easiest way to create a Spring context to use in junit test classes?

Are there strategies for  this covered in the book?

Thanks! :-)

YoungJules

 
A teeny tiny vulgar attempt to get you to buy our stuff
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!