lundi 25 janvier 2016

Unit Test with Springframework test not finishing with Embedded Database

i am developing a project using Spring MVC and Spring MyBatis for my persistence layer, i use the annotations approach, for my services and for MyBatis Mappers. I have wrote several test for my MyBatis Mappers folowing this standard:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:configuration.xml")
public class MyMapperTest{
 .
 .
 .
}

My configuration.xml has a datasource pointing to my postgresql database, so far all my test run smoothly and successfully, it is not appropiate to run my db tests against the real DBMS, so i want to run my tests using a datasource pointing to an embedded database just like this:

<!-- DB configuration -->
<jdbc:embedded-database id="dataSource">
    <jdbc:script location="classpath:schema.sql" />
</jdbc:embedded-database>    

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="typeAliasesPackage" value="mypackage.test" />
</bean>

Oddly, when i make this change in the configuration file that feeds my Unit Test, the test starts .... but never ends.

I can see in the console how the test start to run but then is like the test is frozen, i cant see any log message that guide me to fix this.

I already create another project and use the same configuration that cause the problem and everything works just fine.

I now there are several discussions about the inadequate of writing unit test (integration test better) against database, but is important for my team to test every CRUD operation as in a real production environment, and is not negotiable to stop this embedded-database approach.

Can someone give me a hand?

Aucun commentaire:

Enregistrer un commentaire