-
Jan 27th, 2009, 04:02 AM
#1
Multiple log4j configurations - Application & Test
Hi all,
I have application and test in the same project. Log4j.properties is under src/main/config. What I want is to load another log4j.properties only for testing purposes, for example placed into src/test/config and override the main one. Is it possible? How can I do this?
Thanks in advance for help.
-
Jan 28th, 2009, 03:15 AM
#2
one Possibility would be to use a different log4j configuration file and tell it log4j, just run the Tests with a special System Property
@see http://logging.apache.org/log4j/1.2/manual.html (look for "Default Initialization Procedure" and the Example for Tomcat "Default Initialization under Tomcat")
-
Jan 28th, 2009, 03:56 AM
#3
I need this behaviour also for other properties (hibernate.properties, etc...), because I want a complete different environment for testing. Can you give me some hints to organize my project better?
-
Jan 28th, 2009, 04:26 AM
#4
that is no easy question nor task and depends heavily on your needs
i can only give an example with a multi-module project
- Persistance Project includes SessionFactory for Hibernate + a propertyPlaceHolderConfigurer - see Spring Core Doc, DOES NOT include the referenced dataSource
- Test Project - includes the dataSource Definition for Test with placeHolders e.g. ${db.user} and ${hibernate.show_sql_comments}
- the real project(s) uses Persistance Project AND Test Project, the last one with "test scope" meaning the TestProject.jar is only in the TestLibpath, it includes
(under /src/test/...) a db.properties with those values for ${db.user} etc. the position is hard coded in the propertyPlaceholder e.g.classpath:resources/db.properties
Consequences
- the real Application needs a dataSource Definition for Production Mode, in my Case i use JNDI
- one could use defaults within the propertyPlaceHolderConfigurer with test-Database-Data to make using the db.properties file optional
- one can switch the database and hibernate properties (and more) within the db.properties file on the fly
if you only have one Project you could create the DataSource and Sessionfactory programmatically with selfmade Utilclasses (and/or Spring Annotations)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules