introduction to testing mule

Click here to load reader

Upload: ramakrishna-kapa

Post on 07-Jan-2017

193 views

Category:

Software


0 download

TRANSCRIPT

Introduction to Testing Mule

Types of Testing1.Unit testing2.Integration TestingIntroduction to Testing Mule

Unit TestingUnit testingis a software development process in which the smallest testable parts of an application, called units, are individually and independently scrutinized for proper operation.Unit testingis often automated but it can also be done manually.The concept of unit testing is to validate the correctness of an individual unit of source code.The code you test may interact with other units of code or components, and you should take this possibility into account when designing your unit test. A good unit test should ensure the isolation of the unit of code being tested, to avoid mistaking failure in other components for failure in the unit of code being tested.To isolate your target unit of code, use tools such as themockmessage processor provided by Munit.

Integration Testing

Integration testing(sometimes calledintegrationandtesting, abbreviated I&T) is the phase in softwaretestingin which individual software modules are combined andtestedas a group. It occurs after unittestingand before validationtesting.Units of code collaborate between them to create an actual application. You test individual units of code with unit tests, and you test how units of code collaborate between them withintegration tests.Ideally, integration tests should aggregate units of code modules that have already been successfully unit-tested. For this reason, you should run your integration testsafter your unit tests.

MUnitMunit is a Mule testing framework that lets you easily automate testing Mule applications, using both unit and integration tests. MUnit also provides a set of tools, such as a message processor mocking framework that lets you test units of code in actual isolation.MuleESB provides a Test Compatibility Kit (TCK) ofunit teststhat you can use to test your simple extensions as well as your custom modules and transports.

Testing Mule Custom Components - Legacy Tools for Testing

Mule provides legacy tools for testing your custom Mule applications using Java code. These tools provide the testing functionality but lack some features provided by MUnit, such asmocking.Functional TestingAbstractMuleTestCaseMule also offers tools like theProfiler Pack designed to assist in identifying memory leaks in your custom Mule extensions.

FunctionalTestCase

FunctionalTestCaseis a base test case for Mule functional tests. Your test cases can extend FunctionalTestCaseto use its functionality.FunctionalTestCase fires up a Mule server using a configuration you specify by overriding the getConfigResources():Mule provides an abstractJunit test case calledorg.mule.tck.junit4.FunctionalTestCasethat runs Mule inside a test case and manages the lifecycle of the server.

protected String getConfigResources() { return "mule-conf.xml"; }You can use the methodgetConfigResourcesto specify a configuration file or comma-separated list of configuration files to use. All configuration files must exist in your classpath.

FunctionalTestCaseextends junit.framework.TestCase, so JUnit is the framework for creating and running your test cases. For example, this simple test would send a message to a vm endpointpublic void testSend() throws Exception { MuleClient client = new MuleClient(muleContext); String payload = "foo"; Map properties = null; MuleMessage result = client.send("vm://test", payload, properties); assertEquals("foo Received", result.getPayloadAsString()); }

The use ofMuleClientto interact with the running Mule server.MuleClientis used to send messages to and receive messages from endpoints you specify in your Mule configuration file (mule-conf.xml in this case).

FunctionalTestComponent

The previous example ofFunctionalTestCasecovers many common (synchronous) test scenarios, where the service responds directly to the caller.FunctionalTestComponentcan help support richer tests, such as:Simulating asynchronous communicationReturning mock data to the callerCommon scenarios such as forced exceptions, storing message history, appending text to responses, and delayed responses.The component includes two methods: theonCallmethod and theonReceivemethod that basically do the same thing.onCall: receives a MuleEventContext as input and returns an Object.onReceive: receives an Object as input and returns an Object.

Functional Mule Testing

When it comes to testing the interaction of components between each other in sub flows or simple flows functional tests are the recommended way of testing . Because Mule ESB is light weight and easily embeddable in tests the use of the org.mule.tck.junit4.FunctionalTestCaseclass from the TCK is recommended to test parts or whole flows. This is done by creating a unit test which is derived from this class which will provide an embeddable Mule instance with a Mule context to perform functional tests of these Mule flows.