This week's book giveaway is in the Go forum.
We're giving away four copies of Head First Go and have Jay McGavren on-line!
See this thread for details.
Win a copy of Head First Go this week in the Go 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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

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

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!