webmunit for WebMethods Integration Server This document presents webmunit, a Unit Testing Library developed from scratch on the webmethods Integration Server platform. It also discusses the unit testing strategy in a typical Integration project. It explains how to develop and use webmunit during unit testing, integration testing and performance testing. Finally, this document emphasizes the importance of automation by creating a webmunit that quickly reports on the quality of your integration code for repetitive test process. 1
About the Author Vinay Chandrasekharan Vinay Chandrasekharan is working as Enterprise Architect, has over 7 years of experience in designing and developing Enterprise applications. He also contributes to Open source projects at Apache and elsewhere during his free time. 1
Table of Contents 1. Introduction 3 2. Test Driven Development 3 3. webmunit: A Unit Testing Service on IS 4 4. Building and Running a Sample Test Suite 7 5. Conclusion 9 2
Introduction This article introduces a Unit Testing Library (webmunit) developed from scratch on the webmethods Integration Server platform. It also discusses the unit testing strategy. In a typical Integration project, the complete lifecycle of testing consists of the following types of testing (not in chronological order): Functional Testing Unit testing Integration testing Acceptance testing Non-Functional Testing System testing Regression testing A unit is either a source or a target piece of the integration module. The goals of unit testing are twofold to test the actual code (how the system does what it does) and to test the functionality (what the system does). Unit testing is performed in the initial phases and often throughout the construction phase of the project, using the webmethods Developer tool in a development environment. The unit test plan consists of a series of test scenarios, each developed to test a particular objective that can be mapped to a functional or design requirement. There are several ways to determine the number of test cases you need to ensure adequate coverage. There are several mature and effi cient Unit Testing Libraries available such as JUnit for JAVA-based development projects. But adopting any of those as the base foundation for the Unit Test Flow service on webmethods is highly tedious and cumbersome to manage. webmunit is a collection of a few JAVA and flow services that can be easily used to build and automate Unit Test cases, and facilitate performance testing. Test Driven Development With the advent of new methodologies like Extreme Programming and other agile methodologies, the importance laid upon unit testing has increased. All of these methodologies stress the importance of a good testing strategy. Unit testing or rather any form of testing improves the quality of work. Automating the assembly and building test cases should be done along with the development phase. Continuously integrating and testing against these test cases helps in getting the right feedback about how well and how far the project has progressed. Process documentation may require that developers implement performance testing in their unit tests. When time is at a premium, testing is the fi rst step to be skipped. Generally, functional testing takes a higher priority in integration testing, so there is a tendency to bypass performance testing. Proper design of webmunit will result in automated generation of performance reports against unit tests. The developers implement the components and develop webmunit (using, for example, Java or Flow services). Then, in the testing process, the webmunit can be executed to generate reports detailing the performance of the component code (Code Profi ling), the impact of the component on memory (Memory Profi ling) and the breadth of the unit test (Coverage Profi ling). These reports can be reviewed to ensure that the unit test is actually exercising a high percentage of the code and that there are no gross memory or algorithm errors. webmunit integrates into Ant to allow this automated process to be tightly integrated into build procedures. 3
In fact, most of the methodologies insist on running these test cases many times a day. There is thus a need for aiding developers on webmethods platform with tools and libraries to build and run test cases frequently. webmunit: A Unit Testing Service on IS webmunit provides an automated testing toolkit to: 1. Supply the services to be tested with different, well-thought inputs. 2. Test services involving wm Broker events, for the publish and the subscribe functionality. 3. Execute tests and generate reports highlighting the status of the unit tests from a web-based interface. 4. Validate that the actions or the outputs generated from these services are as per the expectations. 4
To manage various tests conducted on a system, all test cases relevant to a single system are grouped under a test suite. Each test case in turn, consists of a collection of tests to test the sub-system or the component within the system. Throughout the tests, assertions are made to check whether the actions or outputs generated by the system for a given set of inputs are as per the expectations. webmunit enables you to perform unit test components realized as Flow services. Since webmunit is built as a set of Java Flow services, it becomes easy to create and run test cases on the webmethods Integration Server platform. The following table enlists the various features of this library: webmunit: runtestcase Purpose Inputs Outputs Description To compose a Test Suite List of Test Cases (within this test suite) webmunit.document:unittestresults Each typical system would have a test suite that tests various services within it webmunit: runtests Purpose Inputs Outputs Description To compose a Test Case List of Tests (within this test case) None Each test case would contain a set of tests conducted to assert whether the behavior of the service is as per the expectations. webmunit: assertequals Purpose Inputs Outputs Description To assert Actual Value Expected Value Test name None Asserts whether the expected and the actual value matches; if not, an exception is raised. webmunit: assertnotnull Purpose Inputs Outputs Description To assert Object Test Name None Asserts whether the object is not null webmunit: assertnull Purpose Inputs Outputs Description To assert Object Test Name None Asserts whether the object is null 5
webmunit also has an HTML interface to execute a test suite and to view its results. This can be accessed at the following server host: serverport/web/webmunit/index.html. The following fi gure shows the Run webmethods Test Suite page: Run the test suite The only input it requires to run is the fully qualifi ed name of the test suite service. On running the test suite, the JSP-based back-end invokes the relevant webmunit services to generate the HTML report to run the unit tests. The following fi gure shows the results of the test suite: Results of the test suite 6
Building and Running a Sample Test Suite An example to create the necessary unit test artifacts is provided in this section. Consider a simple service that retrieves the next and previous day of the week given the current day namely the getnextday and the getpreviousday service. The following fi gure shows the implementation of the getnextday service: getnextday service. (Note the underlined faulty implementation, which shall be caught latter in unit tests. getpreviousday service can also be implemented in a similar fashion.) Typically, one would test each service with valid and invalid input values to check the way the service behaves under each of these scenarios. Each of the tests written against the service is then clubbed into a test case. For example, to test the getnextday service we can write two tests, namely test_getnextdaywithvalidvalues and test_getnextdaywithinvalidvalues. These tests are then clubbed into a test case namely testcase_ getnextday. One can apply a similar testing strategy for the getpreviousday service. Then, the two test cases for each of these services can be clubbed into a single test suite namely testsuite_sample. 7
Thus, the folder structure for the example along with its test services will look like this: The webmunit package structure (Note the typo mistake in above figure which causes the test to fail for friday as the input) After defi ning all the necessary test artifacts, one can simply run the test suite from the browser or directly from the Developer by running the test suite (testsuite_sample). Now, the test written for the getnextday service, namely test_getnextdaywithvalidvalues shall catch the bug we injected into the implementation. This bug is caught in the unit test performed and the report depicts the same. 8
The following fi gure shows the test results of the failed tests: Test results showing the failed test Conclusion The webmunit toolkit is an excellent tool for creating automated test framework in Situ webmethods development environment. It can be extended to accommodate various unit-testing aspects of the integration and capturing test inputs/outputs. 9
About Enterprise Application Integration Practice With an experience of executing Enterprise Application Integration (EAI) assignments across the globe, a presence in 50+ countries, multiskilled EAI consultants, a rigorous delivery methodology and thorough understanding of the local challenges, TCS is uniquely positioned to provide end-to-end solutions for your EAI needs, and to help you realize the benefi ts of operational excellence within your organization. About Tata Consultancy Services Tata Consultancy Services (TCS) is among the leading global information technology consulting, services and business process outsourcing organizations. Pioneer of the fl exible global delivery model for IT services that enables organizations to operate more effi ciently and produce more value, TCS focuses on delivering technology led business solutions to its international customers across varied industries. For more information contact Ravindra Asundi Tata Consultancy Services Limited, TCS Gateway Park,Akruti Business Port, Road-13, MIDC, Andheri(E), Mumbai-400093 India Phone: +91-22-5550 6826 Email: ravindra.asundi@tcs.com Website : www.tcs.com/eai All content / information present here is the exclusive property of Tata Consultancy Services Limited (TCS). The content / information contained here is correct at the time of publishing. No material from here may be copied, modifi ed, reproduced, republished, uploaded, transmitted, posted or distributed in any form without prior written permission from TCS. Unauthorized use of the content / information appearing here may violate copyright, trademark and other applicable laws, and could result in criminal or civil penalties. Copyright 2004-05 Tata Consultancy Services Limited 10