<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="es">
		<id>https://dosideas.com/wiki/index.php?action=history&amp;feed=atom&amp;title=JUnit_con_bases_de_datos</id>
		<title>JUnit con bases de datos - Historial de revisiones</title>
		<link rel="self" type="application/atom+xml" href="https://dosideas.com/wiki/index.php?action=history&amp;feed=atom&amp;title=JUnit_con_bases_de_datos"/>
		<link rel="alternate" type="text/html" href="https://dosideas.com/wiki/index.php?title=JUnit_con_bases_de_datos&amp;action=history"/>
		<updated>2026-04-27T09:07:14Z</updated>
		<subtitle>Historial de revisiones para esta página en el wiki</subtitle>
		<generator>MediaWiki 1.28.2</generator>

	<entry>
		<id>https://dosideas.com/wiki/index.php?title=JUnit_con_bases_de_datos&amp;diff=6507&amp;oldid=prev</id>
		<title>Admin: /* La regla de JUnit */</title>
		<link rel="alternate" type="text/html" href="https://dosideas.com/wiki/index.php?title=JUnit_con_bases_de_datos&amp;diff=6507&amp;oldid=prev"/>
				<updated>2012-02-24T12:34:04Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;La regla de JUnit&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;' lang='es'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Revisión anterior&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revisión del 12:34 24 feb 2012&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l78&quot; &gt;Línea 78:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Línea 78:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==== La regla de JUnit ====&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==== La regla de JUnit ====&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Luego, crearemos una regla de [[JUnit]] que buscará esta anotación, y si la encuentra, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;limpiará &lt;/del&gt;la base de datos: &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Luego, crearemos una regla de [[JUnit]] que buscará esta anotación, y si la encuentra, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;reconstruye la base de datos. Esta regla usa una instancia de DatabaseRebuilder para hacer la reconstrucción de &lt;/ins&gt;la base de datos: &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;code java5&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;code java5&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;public class DirtiesDatabaseRule implements TestRule {&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;public class DirtiesDatabaseRule implements TestRule {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>https://dosideas.com/wiki/index.php?title=JUnit_con_bases_de_datos&amp;diff=6506&amp;oldid=prev</id>
		<title>Admin: /* La regla de JUnit */</title>
		<link rel="alternate" type="text/html" href="https://dosideas.com/wiki/index.php?title=JUnit_con_bases_de_datos&amp;diff=6506&amp;oldid=prev"/>
				<updated>2012-02-23T20:50:14Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;La regla de JUnit&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;' lang='es'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Revisión anterior&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revisión del 20:50 23 feb 2012&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l67&quot; &gt;Línea 67:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Línea 67:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/code&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/code&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==== &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;La regla &lt;/del&gt;de &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;JUnit &lt;/del&gt;====&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==== &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;DatabaseRebuilder para reconstruir la base &lt;/ins&gt;de &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;datos &lt;/ins&gt;====&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Primera &lt;/del&gt;vamos a crear una interfaz para una clase que se encargue de reconstruir la base de datos: &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Primero &lt;/ins&gt;vamos a crear una interfaz para una clase que se encargue de reconstruir la base de datos: &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;code java5&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;code java5&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;public interface DatabaseRebuilder {&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;public interface DatabaseRebuilder {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l75&quot; &gt;Línea 75:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Línea 75:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/code&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/code&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Una posible implementación de esta interfaz podría ser invocar a los scripts de inicialización de la base en memoria. &lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;==== La regla de JUnit ====&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Luego, crearemos una regla de [[JUnit]] que buscará esta anotación, y si la encuentra, limpiará la base de datos: &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Luego, crearemos una regla de [[JUnit]] que buscará esta anotación, y si la encuentra, limpiará la base de datos: &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;code java5&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;code java5&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>https://dosideas.com/wiki/index.php?title=JUnit_con_bases_de_datos&amp;diff=6505&amp;oldid=prev</id>
		<title>Admin: Página creada con 'Es muy común tener que integrar JUnit para ejecutar tests contra una base de datos. Vamos a ver algunas facilidades que nos provee JUnit y Spring Framework para hac…'</title>
		<link rel="alternate" type="text/html" href="https://dosideas.com/wiki/index.php?title=JUnit_con_bases_de_datos&amp;diff=6505&amp;oldid=prev"/>
				<updated>2012-02-23T20:16:04Z</updated>
		
		<summary type="html">&lt;p&gt;Página creada con &amp;#039;Es muy común tener que integrar &lt;a href=&quot;/wiki/JUnit&quot; title=&quot;JUnit&quot;&gt;JUnit&lt;/a&gt; para ejecutar tests contra una base de datos. Vamos a ver algunas facilidades que nos provee &lt;a href=&quot;/wiki/JUnit&quot; title=&quot;JUnit&quot;&gt;JUnit&lt;/a&gt; y &lt;a href=&quot;/wiki/Spring_Framework&quot; title=&quot;Spring Framework&quot;&gt;Spring Framework&lt;/a&gt; para hac…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Página nueva&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Es muy común tener que integrar [[JUnit]] para ejecutar tests contra una base de datos. Vamos a ver algunas facilidades que nos provee [[JUnit]] y [[Spring Framework]] para hacer más facil la ejecución de tests contra datos siempre limpios. &lt;br /&gt;
&lt;br /&gt;
== embedded-database de Spring ==&lt;br /&gt;
[[Spring Framework]] contiene una utilidad para levantar bases de datos en memoria al momento que se inicializa el factory. De esta forma, podemos inicializar una base y a la vez decirle que ejecute varios scripts, para dejarla preparada y lista para usar. &lt;br /&gt;
&lt;br /&gt;
Un archivo de configuración de ejemplo: &lt;br /&gt;
&amp;lt;code xml&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;beans xmlns=&amp;quot;http://www.springframework.org/schema/beans&amp;quot;&lt;br /&gt;
       xmlns:xsi=&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot;&lt;br /&gt;
       xmlns:jdbc=&amp;quot;http://www.springframework.org/schema/jdbc&amp;quot;&lt;br /&gt;
       xsi:schemaLocation=&amp;quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd&lt;br /&gt;
       http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;jdbc:embedded-database id=&amp;quot;dataSource&amp;quot; type=&amp;quot;HSQL&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;jdbc:initialize-database data-source=&amp;quot;dataSource&amp;quot; ignore-failures=&amp;quot;NONE&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;jdbc:script location=&amp;quot;classpath:tablas.sql&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;jdbc:script location=&amp;quot;classpath:datos.sql &amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/jdbc:initialize-database&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/beans&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Esta configuración crea un bean llamada &amp;quot;dataSource&amp;quot; que es un DataSource común, listo para inyectar en nuestra aplicación (y reemplazar así un DataSource real). Este DataSource apunta a una base en memoria HSQLDB, y ejecutarán 2 scripts al momento de inicialización: tablas.sql y datos.sql&lt;br /&gt;
&lt;br /&gt;
== Limpieza del contexto de Spring en los tests ==&lt;br /&gt;
Es posible que algún método de test &amp;quot;ensucie&amp;quot; (cambie) el valor de algún bean del factory, lo cual ocasione problemas en tests posteriores. Podemos usar la anotación @DirtiesContext para indicarle a Spring que vuelva a crear un nuevo factory luego de la ejecución del método anotado con esta anotación. &lt;br /&gt;
&lt;br /&gt;
Por ejemplo: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code java5&amp;gt;&lt;br /&gt;
@RunWith(SpringJUnit4ClassRunner.class)&lt;br /&gt;
@ContextConfiguration(locations = {&lt;br /&gt;
    &amp;quot;classpath:datasource-test.xml&amp;quot;,&lt;br /&gt;
    &amp;quot;classpath:applicationContext.xml&amp;quot;&lt;br /&gt;
})&lt;br /&gt;
public class MiTest {&lt;br /&gt;
&lt;br /&gt;
    @Test&lt;br /&gt;
    public void fooTest() { ... }&lt;br /&gt;
&lt;br /&gt;
    @Test&lt;br /&gt;
    @DirtiesContext&lt;br /&gt;
    public void barTest() { ... }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
En este ejemplo, al terminar la ejecución del método barTest() se volverá a crear el factory de Spring (y por lo tanto, se creará una nueva base en memoria). De esta manera el resto de los métodos contarán con un entorno limpio. &lt;br /&gt;
&lt;br /&gt;
== Limpieza de la base de datos con Rules de JUnit ==&lt;br /&gt;
&lt;br /&gt;
En la mayoría de las ocasiones, los métodos @Test no ensucian el contexto de beans de Spring, sino que ensucian los datos de la base de datos (realizando inserts, updates, deletes sobre los mismos). Los métodos posteriores de tests podrían verse afectados por no contar con los datos tal cual se los esperaba. &lt;br /&gt;
&lt;br /&gt;
Una solución es anotar a estos tests que ensucian la base de datos con @DirtiesContext. Esto forzará la creación de un nuevo contexto de Spring, y se recreará la correspondiente base de datos en memoria. Sin embargo, esta solución es relativamente costosa por la continua destrucción/construcción del factory de Spring. &lt;br /&gt;
&lt;br /&gt;
Una solución alternativa será usar un @DirtiesDatabase que sólo recree la base de datos en memoria... sin embargo, Spring no tiene esta utilidad. Por suerte, es muy simple agregarla. &lt;br /&gt;
&lt;br /&gt;
=== @DirtiesDatabase ===&lt;br /&gt;
Crearemos una anotación de método que nos permita indicar que un método de @Test ensucia la base de datos, y luego usaremos una Regla de [[JUnit]] para leer esta anotación y hacer la limpiaza necesaria. &lt;br /&gt;
&lt;br /&gt;
==== La anotación ====&lt;br /&gt;
La anotación es común: &lt;br /&gt;
&amp;lt;code java5&amp;gt;&lt;br /&gt;
@Retention(RetentionPolicy.RUNTIME)&lt;br /&gt;
public @interface DirtiesDatabase { }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== La regla de JUnit ====&lt;br /&gt;
Primera vamos a crear una interfaz para una clase que se encargue de reconstruir la base de datos: &lt;br /&gt;
&amp;lt;code java5&amp;gt;&lt;br /&gt;
public interface DatabaseRebuilder {&lt;br /&gt;
    void rebuildDatabase();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Luego, crearemos una regla de [[JUnit]] que buscará esta anotación, y si la encuentra, limpiará la base de datos: &lt;br /&gt;
&amp;lt;code java5&amp;gt;&lt;br /&gt;
public class DirtiesDatabaseRule implements TestRule {&lt;br /&gt;
&lt;br /&gt;
    private DatabaseRebuilder rebuilder;&lt;br /&gt;
&lt;br /&gt;
    public DirtiesDatabaseRule(DatabaseRebuilder rebuilder) {&lt;br /&gt;
        this.rebuilder = rebuilder;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    @Override&lt;br /&gt;
    public Statement apply(final Statement base, final Description description) {&lt;br /&gt;
        return new Statement() {&lt;br /&gt;
            @Override&lt;br /&gt;
            public void evaluate() throws Throwable {&lt;br /&gt;
                try {&lt;br /&gt;
                    base.evaluate();&lt;br /&gt;
                } finally {&lt;br /&gt;
                    DirtiesDatabase dirtiesDatabase = description.getAnnotation(DirtiesDatabase.class);&lt;br /&gt;
                    if (dirtiesDatabase != null) {&lt;br /&gt;
                        rebuilder.rebuildDatabase();&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        };&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Usando @DirtiesDatabase ====&lt;br /&gt;
Listo! Nos queda agregar la regla a la clase de test, y la anotación correspondiente. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code java5&amp;gt;&lt;br /&gt;
@RunWith(SpringJUnit4ClassRunner.class)&lt;br /&gt;
@ContextConfiguration(locations = {&lt;br /&gt;
    &amp;quot;classpath:datasource-test.xml&amp;quot;,&lt;br /&gt;
    &amp;quot;classpath:applicationContext.xml&amp;quot;&lt;br /&gt;
})&lt;br /&gt;
public class MiTest {&lt;br /&gt;
&lt;br /&gt;
    @Rule&lt;br /&gt;
    public DirtiesDatabaseRule dirtiesDatabaseRule = new DirtiesDatabaseRule(new DatabaseRebuilderImpl());&lt;br /&gt;
&lt;br /&gt;
    @Test&lt;br /&gt;
    public void fooTest() { ... }&lt;br /&gt;
&lt;br /&gt;
    @Test&lt;br /&gt;
    @DirtiesDatabase&lt;br /&gt;
    public void barTest() { ... }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>