EasyTest : Spring Integration

anujgandharv edited this page Nov 7, 2012 · 7 revisions

EasyTest team understands the importance of Integration testing in the Software Development environment and also appreciate the efforts of Spring in providing a convenient framework to perform Integration testing using JUnit as the implementation behind the scene.

EasyTest has taken the Spring Integration Testing to a whole new level, where the users can now write Data Driven Integration Tests just as they write the normal unit tests.

This wiki will talk about how you can enable the support of Data Driven Testing in Spring Integration Test Library, and will show how simple and hassle free it is to enable Data Driven Integration Testing using Spring.

First lets look at what is required to write a Spring Integration Test in a normal non-easytest enabled environment. This is a simple test class that you would write when writing Spring Integration Tests

          @RunWith(SpringJUnit4ClassRunner.class)
          @ContextConfiguration(classes = { XmlBusinessConfig.class }, loader = AnnotationConfigContextLoader.class)
          @TransactionConfiguration(transactionManager="transactionManager" )
          @Transactional
          public class EasyTestSpringExample {
             ........//Your test methods

As you can see, we are using AnnotationConfigContextLoader to load bean definitions from a Java Class and we are enabling transactions to be used on our test methods.

In order to enable Data Driven Testing with Spring, the only things you have to do is :

  • Use SpringTestRunner instead of SpringJUnit4ClassRunner in the RunWith annotation , and

  • Use @DataLoader annotation to specify the usual things of where to load the data from and what loader to use.

Thus the above Configuration changes to :

            @RunWith(SpringTestRunner.class)
             @DataLoader(filePaths = { "input-data.xml" }, loaderType = LoaderType.XML)
             @ContextConfiguration(classes = { XmlBusinessConfig.class }, loader = AnnotationConfigContextLoader.class)
             @TransactionConfiguration(transactionManager="transactionManager" )
             @Transactional
             public class EasyTestSpringExample {

And thats it. You can now start writing Data Driven Integration tests using Spring. Here is a complete example of writing Spring Data Driven Integration tests: https://github.com/EaseTech/easytest-samples/blob/master/src/test/java/org/easetech/easytest/spring/example/TestSpringConfiguration.java

Happy EasyTest(ing)