Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Overview of testing a Spring Framework application

 
Ranch Hand
Posts: 90
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How are Spring Framework applications normally tested?

Also, suppose that the application uses external resources such as a database and that for the purposes of testing, you want to use a test database so as not to inadvertently affect the production database. How does Spring Framework solve the problem of switching between testing and production configurations?

Is there a section on testing in Spring in Action?

Daniel
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel,

There are multiple ways of solving this problem
a) You can store your database related settings in a configuration file, and then use the PropertyPlaceHolderCOnfigurer to "inject" the properties from the configuration file into the Spring XML
b) You can use Spring Profiles to have a Configuration for each environment. So, for example, if you look up datasource through JNDI, and you don;t have JNDI available for unit testing, you can use Spring profiles to specify the Datasource in the Spring XML during unit test

Most people use a combination of the 2
 
author
Posts: 396
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You can configure an embedded database in Spring, so that tests can hit that database instead of the production or other database server. Then, using Spring's support for runtime profiles, you can make a decision as to which database you'll use: embedded in development, QA datasource in QA, or production datasource in production. Spring in Action does cover profiles.

As for a specific section on testing? No. But testing is shown several places throughout the book as it pertains to the subjects at hand.

Daniel Trebbien wrote:Hi,

How are Spring Framework applications normally tested?

Also, suppose that the application uses external resources such as a database and that for the purposes of testing, you want to use a test database so as not to inadvertently affect the production database. How does Spring Framework solve the problem of switching between testing and production configurations?

Is there a section on testing in Spring in Action?

Daniel

 
Daniel Trebbien
Ranch Hand
Posts: 90
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Craig,

Thanks for your reply. It sounds like Spring Profiles are an excellent solution for switching between testing and production configurations. It sounds more general, too. As you mention, it could be used to create a development profile that uses an embedded database and other embedded resources, so there are less external dependencies during development.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!