|
Fornax-Platform
Forum |
« Return to Thread: Configuration/running Unit Tests
By default we use hsqldb inmemory database with dbunit for unit testing.
To use same configuration for test as for production you can add the following annotation to your unit test class (which is extending AbstractDbUnitJpaTests)
@ContextConfiguration(locations={"classpath:applicationContext.xml"}, inheritLocations=false)
I doubt that using real oracle for junit test is a good approach, but maybe a few integration tests using a real database is reasonable.
All 3 samples (library, DDDSample, and helloworld) have junit test examples, using the default approach with hsqldb.
/Patrik
PS. I will soon write something about how to use Mockito together with Spring/Sculptor.deepshar027 wrote:Hey Guys,
I have been working diligently to run a unit test after code generation from sculptor(version 1.6).Havent been there yet.
few queries.
1) I see there is difference in config files generated for main and test with regards to EntityManagerFactory.xml specifically.
for e.g Test file has a datasource specified while main file doesnt.
Also following bean is specified in test EntitymanagerFactory.xml but not in main.
<bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
<property name="defaultDataSource" ref="hsqldbDataSource"/>
<property name="persistenceXmlLocations">
<list>
<value>classpath:META-INF/persistence-test.xml</value>
</list>
</property>
</bean>
I want to have my main EntitymanagerFactory.xml file have same stuff its there in test file.Not sure why there is discrepency.
2) The tests file uses hsqldb by default.Is there a way I can override that to use oracle for tests as well?
3) When I run my tests I get an error
14:20:29,984 INFO UserServiceTest:162 - Custom transaction definition [PROPAGAT
ION_REQUIRED,ISOLATION_DEFAULT] for test method [testCreateAccount].
14:20:29,984 INFO UserServiceTest:175 - ApplicationContext has not been configu
red for test [com.bookonz.account.serviceapi.UserServiceTest]: dependency inject
ion will NOT be performed.
I think this is becoz I need to define the test bean(UserServiceTest) in applicationContext.xml and configure transaction params.
Do you guys have any working example of this?
I really want to get past configuring spring/hibernate/jpa stuff and be able to run a few tests.
Thanks,
Deepak
« Return to Thread: Configuration/running Unit Tests
| Free embeddable forum powered by Nabble | Forum Help |