Sunday, 15 April 2012

java - Spring configuration launch before each unit test for the same test class -



java - Spring configuration launch before each unit test for the same test class -

i seek integrate hsqldb (memory db) in project, because beginning, dao tested real database , not safe, because when database not up, jenkins failed test!

but see unusual when launch test class.

i have 3 test in class , when doing run junit test eclipse, see spring configuration reloaded before each unit test. normal? because have utilize

<prop key="hibernate.hbm2ddl.import_files">import.sql</prop>

and file contain many create table, , when sec test launch, see error messages : "table toto exist..."

does possible have spring configuration loaded 1 test in class?

here configuration :

<bean name="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource"> <property name="driverclassname" value="org.hsqldb.jdbcdriver" /> <property name="url" value="jdbc:hsqldb:mem:castor;syntax.ora=true" /> <property name="username" value="sa" /> <property name="password" value="" /> </bean> <bean id="hibernatesessionfactory" class="org.springframework.orm.hibernate3.localsessionfactorybean"> <property name="mappinglocations" value="classpath*:fr/**/*.hbm.xml"/> <property name="hibernateproperties"> <props> <prop key="hibernate.dialect">fr.edf.mpv2.castor.persistance.hsqloracledialect</prop> <prop key="hibernate.show_sql">false</prop> <prop key="hibernate.hbm2ddl.auto">create</prop> <prop key="hibernate.hbm2ddl.import_files">import.sql</prop> <prop key="hibernate.format_sql">false</prop> <prop key="hibernate.bytecode.use_reflection_optimizer">true</prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.nocacheprovider</prop> </props> </property> <property name="datasource" ref="datasource"/> </bean> <bean id="transactionmanager" class="org.springframework.jdbc.datasource.datasourcetransactionmanager"> <constructor-arg ref="datasource"/> <property name="rollbackoncommitfailure" value="true"/> </bean>

its legacy project, , people start project spring doesn't know how work, doesn't utilize injection :( , create mill load spring configuration instead of utilize applicationcontext.xml...

so help developper have create mock override mill in test context

here declaration :

public class maildaotest extends beanfactoryoverrider { .... @runwith(powermockrunner.class) @preparefortest({ beanfactory.class }) @powermockignore("javax.management.*") public class beanfactoryoverrider { /** context spring de test. */ private applicationcontext applicationcontext;

so everywhere in code utilize mill own springcontext, override method utilize own spring context own configuration , not real production configuration. work fine, explain why m using powerkmockrunner ;)

i utilize spring 2.0 / hibernate 3.2.6 / hsql 2.3.2

thanks lot help!

if specify context configuration location on test class, , utilize spring test runner context cached not reloaded each time.

something :

@runwith (springjunit4classrunner.class) @contextconfiguration (locations = "classpath:/config/applicationcontext-test.xml") @webappconfiguration public class mytest {}

java spring hibernate junit hsqldb

No comments:

Post a Comment