|
|
|
|
@ -179,7 +179,7 @@
@@ -179,7 +179,7 @@
|
|
|
|
|
linkend="testcontext-framework">Spring TestContext Framework</link>. The |
|
|
|
|
TestContext Framework is agnostic of the actual testing framework in |
|
|
|
|
use, thus allowing instrumentation of tests in various environments |
|
|
|
|
including JUnit 3.8, JUnit 4.5, TestNG, etc.</para> |
|
|
|
|
including JUnit 3.8, JUnit 4.6, TestNG, etc.</para> |
|
|
|
|
|
|
|
|
|
<note> |
|
|
|
|
<title>Legacy JUnit 3.8 class hierarchy is deprecated</title> |
|
|
|
|
@ -393,7 +393,7 @@
@@ -393,7 +393,7 @@
|
|
|
|
|
simplify standard database testing scenarios. <emphasis>Note that <link |
|
|
|
|
linkend="testcontext-support-classes-junit38"><classname>AbstractTransactionalJUnit38SpringContextTests</classname></link>, |
|
|
|
|
<link |
|
|
|
|
linkend="testcontext-support-classes-junit45"><classname>AbstractTransactionalJUnit4SpringContextTests</classname></link>, |
|
|
|
|
linkend="testcontext-support-classes-junit4"><classname>AbstractTransactionalJUnit4SpringContextTests</classname></link>, |
|
|
|
|
and <link |
|
|
|
|
linkend="testcontext-support-classes-testng"><classname>AbstractTransactionalTestNGSpringContextTests</classname></link> |
|
|
|
|
provide convenience methods which delegate to |
|
|
|
|
@ -571,7 +571,7 @@ public void testProcessWithoutTransaction() {
@@ -571,7 +571,7 @@ public void testProcessWithoutTransaction() {
|
|
|
|
|
when used in conjunction with JUnit (i.e., with the <link |
|
|
|
|
linkend="testcontext-junit4-runner">SpringJUnit4ClassRunner</link> or |
|
|
|
|
the <link linkend="testcontext-support-classes-junit38">JUnit 3.8</link> |
|
|
|
|
and <link linkend="testcontext-support-classes-junit45">JUnit 4.5</link> |
|
|
|
|
and <link linkend="testcontext-support-classes-junit4">JUnit 4.6</link> |
|
|
|
|
support classes.</para> |
|
|
|
|
|
|
|
|
|
<itemizedlist> |
|
|
|
|
@ -761,15 +761,15 @@ public void testProcessRepeatedly() {
@@ -761,15 +761,15 @@ public void testProcessRepeatedly() {
|
|
|
|
|
<literal>org.springframework.test.context</literal> package) provides |
|
|
|
|
generic, annotation-driven unit and integration testing support that is |
|
|
|
|
agnostic of the testing framework in use, for example JUnit 3.8, JUnit |
|
|
|
|
4.5, TestNG 5.8, etc. The TestContext framework also places a great deal |
|
|
|
|
4.6, TestNG 5.8, etc. The TestContext framework also places a great deal |
|
|
|
|
of importance on <emphasis>convention over configuration</emphasis> with |
|
|
|
|
reasonable defaults that can be overridden via annotation-based |
|
|
|
|
configuration.</para> |
|
|
|
|
|
|
|
|
|
<para>In addition to generic testing infrastructure, the TestContext |
|
|
|
|
framework provides explicit support for JUnit 3.8, JUnit 4.5, and TestNG |
|
|
|
|
framework provides explicit support for JUnit 3.8, JUnit 4.6, and TestNG |
|
|
|
|
5.8 in the form of <literal>abstract</literal> support classes. For |
|
|
|
|
JUnit 4.5, the framework also provides a custom |
|
|
|
|
JUnit 4.6, the framework also provides a custom |
|
|
|
|
<interfacename>Runner</interfacename> which allows one to write test |
|
|
|
|
classes that are not required to extend a particular class |
|
|
|
|
hierarchy.</para> |
|
|
|
|
@ -1060,11 +1060,11 @@ public class ExtendedTest extends BaseTest {
@@ -1060,11 +1060,11 @@ public class ExtendedTest extends BaseTest {
|
|
|
|
|
<para>Consider the scenario where we have a class, |
|
|
|
|
<classname>HibernateTitleDao</classname> (as outlined in the <link |
|
|
|
|
linkend="testing-fixture-di">Goals</link> section). First, let's look |
|
|
|
|
at a JUnit 4.5 based implementation of the test class itself which |
|
|
|
|
at a JUnit 4.6 based implementation of the test class itself which |
|
|
|
|
uses <interfacename>@Autowired</interfacename> for field injection (we |
|
|
|
|
will look at the application context configuration after all sample |
|
|
|
|
code listings). <emphasis>Note: The dependency injection behavior in |
|
|
|
|
the following code listings is not in any way specific to JUnit 4.5. |
|
|
|
|
the following code listings is not in any way specific to JUnit 4.6. |
|
|
|
|
The same DI techniques can be used in conjunction with any testing |
|
|
|
|
framework.</emphasis></para> |
|
|
|
|
|
|
|
|
|
@ -1264,7 +1264,7 @@ public final class HibernateTitleDaoTests {
@@ -1264,7 +1264,7 @@ public final class HibernateTitleDaoTests {
|
|
|
|
|
<para><emphasis>Note that <link |
|
|
|
|
linkend="testcontext-support-classes-junit38"><classname>AbstractTransactionalJUnit38SpringContextTests</classname></link>, |
|
|
|
|
<link |
|
|
|
|
linkend="testcontext-support-classes-junit45"><classname>AbstractTransactionalJUnit4SpringContextTests</classname></link>, |
|
|
|
|
linkend="testcontext-support-classes-junit4"><classname>AbstractTransactionalJUnit4SpringContextTests</classname></link>, |
|
|
|
|
and <link |
|
|
|
|
linkend="testcontext-support-classes-testng"><classname>AbstractTransactionalTestNGSpringContextTests</classname></link> |
|
|
|
|
are pre-configured for transactional support at the class level. |
|
|
|
|
@ -1418,11 +1418,11 @@ public class FictitiousTransactionalTest {
@@ -1418,11 +1418,11 @@ public class FictitiousTransactionalTest {
|
|
|
|
|
</itemizedlist> |
|
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
<section id="testcontext-support-classes-junit45"> |
|
|
|
|
<title>JUnit 4.5 support classes</title> |
|
|
|
|
<section id="testcontext-support-classes-junit4"> |
|
|
|
|
<title>JUnit 4.6 support classes</title> |
|
|
|
|
|
|
|
|
|
<para>The <literal>org.springframework.test.context.junit4</literal> |
|
|
|
|
package provides support classes for JUnit 4.5 based test |
|
|
|
|
package provides support classes for JUnit 4.6 based test |
|
|
|
|
cases.</para> |
|
|
|
|
|
|
|
|
|
<itemizedlist> |
|
|
|
|
@ -1432,7 +1432,7 @@ public class FictitiousTransactionalTest {
@@ -1432,7 +1432,7 @@ public class FictitiousTransactionalTest {
|
|
|
|
|
<para>Abstract base test class which integrates the |
|
|
|
|
<emphasis>Spring TestContext Framework</emphasis> with explicit |
|
|
|
|
<classname>ApplicationContext</classname> testing support in a |
|
|
|
|
JUnit 4.5 environment.</para> |
|
|
|
|
JUnit 4.6 environment.</para> |
|
|
|
|
|
|
|
|
|
<para>When you extend |
|
|
|
|
<classname>AbstractJUnit4SpringContextTests</classname> you will |
|
|
|
|
@ -1502,13 +1502,13 @@ public class FictitiousTransactionalTest {
@@ -1502,13 +1502,13 @@ public class FictitiousTransactionalTest {
|
|
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
<section id="testcontext-junit4-runner"> |
|
|
|
|
<title>Custom JUnit 4.5 Runner</title> |
|
|
|
|
<title>Custom JUnit 4.6 Runner</title> |
|
|
|
|
|
|
|
|
|
<para>The <emphasis>Spring TestContext Framework</emphasis> offers |
|
|
|
|
full integration with JUnit 4.5 via a custom runner. By annotating |
|
|
|
|
full integration with JUnit 4.6 via a custom runner. By annotating |
|
|
|
|
test classes with |
|
|
|
|
<literal>@Runwith(SpringJUnit4ClassRunner.class)</literal>, |
|
|
|
|
developers can implement standard JUnit 4.5 unit and integration |
|
|
|
|
developers can implement standard JUnit 4.6 unit and integration |
|
|
|
|
tests and simultaneously reap the benefits of the TestContext |
|
|
|
|
framework such as support for loading application contexts, |
|
|
|
|
dependency injection of test instances, transactional test method |
|
|
|
|
@ -1627,7 +1627,7 @@ public class SimpleTest {
@@ -1627,7 +1627,7 @@ public class SimpleTest {
|
|
|
|
|
|
|
|
|
|
<para>The PetClinic sample application included with the full Spring |
|
|
|
|
distribution illustrates several features of the <emphasis>Spring |
|
|
|
|
TestContext Framework</emphasis> in a JUnit 4.5 environment. Most test |
|
|
|
|
TestContext Framework</emphasis> in a JUnit 4.6 environment. Most test |
|
|
|
|
functionality is included in the |
|
|
|
|
<classname>AbstractClinicTests</classname>, for which a partial listing |
|
|
|
|
is shown below:</para> |
|
|
|
|
@ -1767,7 +1767,7 @@ public class HibernateClinicTests extends AbstractClinicTests { }
@@ -1767,7 +1767,7 @@ public class HibernateClinicTests extends AbstractClinicTests { }
|
|
|
|
|
<listitem> |
|
|
|
|
<para><ulink url="http://www.junit.org/">JUnit</ulink>: the Spring |
|
|
|
|
Framework's unit and integration test suite is written using JUnit 3.8 |
|
|
|
|
and JUnit 4.5 as the testing framework.</para> |
|
|
|
|
and JUnit 4.6 as the testing framework.</para> |
|
|
|
|
</listitem> |
|
|
|
|
|
|
|
|
|
<listitem> |
|
|
|
|
|