version="1.0"encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:sec="http://www.springframework.org/schema/security" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <context:annotation-config /> <context:component-scan base-package="br.com.blogspot.javanapratica.spring"/> <bean id="transactionManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> <bean id="sessionFactory"class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="configLocation"> <value>classpath:hibernate-test.cfg.xml</value> </property> <property name="configurationClass"> <value>org.hibernate.cfg.AnnotationConfiguration</value> </property> <property name="packagesToScan" value="br.com.blogspot.javanapratica.domain"/> </bean></beans> Este arquivo realiza o scan dos diretorios nos quais se encontram classes anotadas pelo spring e define uma fabrica de sessoes que tambem contem diretrizes para escanear outro diretorio, o do modelo. Este mesmo bean da fabrica indica outro arquivo que vamos exibir na Listagem 2 que e o "hibernate-teste.cfg.xml". Listagem2<?xml version="1.0"encoding="UTF-8"?><!DOCTYPE hibernate-configurationPUBLIC "-//Hibernate/HibernateConfiguration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"><hibernate-configuration> <session-factory> <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property> <property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property> <property name="hibernate.default_schema">public</property> <property name="hibernate.connection.url">jdbc:hsqldb:mem:javanapratica</property> <property name="hibernate.connection.username">javanapratica</property> <property name="hibernate.connection.password">123</property> <property name="hibernate.connection.useUnicode">true</property> <property name="hibernate.connection.characterEncoding">UTF-8</property> <property name="hibernate.show_sql">false</property> <property name="hibernate.use_sql_comments">false</property> <property name="hibernate.format_sql">true</property> <property name="hibernate.generate_statistics">false</property> <property name="hibernate.hbm2ddl.auto">update</property> <property name="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider</property> <property name="hibernate.search.default.indexBase">/usr/lib/apache-tomcat/webapps/lucene-indices/javanapratica-test-indice/</property> <property name="hibernate.search.worker.batch_size">1</property> </session-factory></hibernate-configuration> Muito importante notar no arquivo acima a definicao de uma conexao com o banco HSQLDB em memoria que e criado toda vez que se inicia os testes. Por ultimo na Listagem 3 temos um exemplo de uma classe de testes com as suas respectivas anotacoes pertinentes ao DI do Spring.Listagem 3@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration("/applicationContext4JUnit.xml") public class SpringTest { @Autowired private JavaNaPraticaBO bo; @Test public void javanapratica() { Assert.assertTrue(true); }}ConclusaoApesar de simples a dica deste post pode orientar a todos que estao iniciando no teste de unidades com Spring e Java. Boa sorte !!!