munit - introduction

18
MUnit Introduction into Automated Testing of Apps In Anypoint Studio

Upload: dasail

Post on 17-Aug-2015

34 views

Category:

Internet


1 download

TRANSCRIPT

MUnit

Introduction into Automated Testing of Apps

In Anypoint Studio

Test my apps? Why would I?

Tests should be applied during each phase of the software development process from developer tests to acceptance tests.

In software engineering comprehensive and automated test suits will secure the quality of software and can provide a safety net for regression and incompatibility changes.

The Testing Pyramid

Ideally testing of software projects is built bottom up. Starting with a large test case base of automated unit tests for the smallest components which make up the whole application together.

Going up through architecture layers the number of test cases decreases for larger components because they are compositions of the already tested components.

Reaching finally the top of the pyramid where manual supervision or manual tests make up the top of the pyramid testing the application as a whole

*http://martinfowler.com/bliki/TestPyramid.html*http://watirmelon.com/2012/01/31/introducing-the-software-

testing-ice-cream-cone/

Unit Tests

On the lowest level unit tests verify the correct functionality of classes. These classes can be in a Mule project simple extensions and customizations of the Mule framework. Unit tests in a classical sense can test the functionality of custom classes without firing up Mule.

Single Unit

* https://blog.codecentric.de/en/2015/01/mule-esb-testing-part-13-unit-functional-testing/

Functional Tests

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.

Single Unit Single UnitSingle Unit

* https://blog.codecentric.de/en/2015/01/mule-esb-testing-part-13-unit-functional-testing/

What is MUnit ?

MUnit is a Mule testing framework which allows Mule developers to easily automate testing. It is an open-source project, created originally as a side project in Mule.

* https://developer.mulesoft.com/docs/display/current/MUnit

Munit will allow you to:Create your Mule test by writing Mule code.Create your Mule test by writing Java code.Disable flow inbound endpoints.Disable endpoint connectors.Mock outbound endpoints.Mock message processors.Spy any message processor.Verify message processor callsCreate not only unit tests but also integration tests in a local environment .

 MUnit allows you to start a local FTP/SFTP, DB server or mail server.Call the Mule client from Mule code.Assert flow exceptions.Enable or disable particular tests.See assertion/error reports with Mule stack trace.Extend the MUnit framework with plugins.Check visual coverage in Studio.Debug your tests with Studio.

* https://developer.mulesoft.com/docs/display/current/MUnit

Installing MUnitTo install MUnit, follow these steps:

Verify that your version of Studio is 5.2.0 (July 2015 release) or above.Add the MUnit update site:

http://studio.mulesoft.org/r4/munit

Go to Help -> Install New Software.Studio displays the Available Software window. In the Work with: field, paste the MUnit update siteCheck Munit and Munit Tools for Mule.Using MUnit automatically adds a new folder, src/test/munit, to your project.* https://developer.mulesoft.com/docs/display/current/Using+MUnit+in+Anypoint+Studio

Creating a New MUnit Test in Studio

MUnit Studio integration is mainly built around XML-based tests. Most of the MUnit-Studio integration tools guide you in the creation of these tests.

There are two basic ways to create a new MUnit test in Studio:

1. Right-click a specific flow by right clicking the flow and selecting MUnit

2. Use the wizard, which allows you to create a test for any flow or application in the workspace

The most basic ones are by right-clicking the flow you want to test, or by using the wizard.

* https://developer.mulesoft.com/docs/display/current/Using+MUnit+in+Anypoint+Studio

Creating a Test for a Specific Flow

To create a test for a specific flow, right-click the flow, then select:MUnit -> Create a new <flow_name> suite

This Creates a new test suite named after the XML file where the flow resides, in this case munit2.xml. Studio displays the test suite on a new tab, next to the tab for the original application, imports the XML file to the test suite and creates a new MUnit test.

To add an MUnit message processor to the test as described above, drag it from the Palette to the Test area after the flow-ref.

* https://developer.mulesoft.com/docs/display/current/Using+MUnit+in+Anypoint+Studio

This creates the following XML:<?xml version="1.0" encoding="UTF-8"?><mule xmlns="http://www.mulesoft.org/schema/mule/core"

xmlns:munit="http://www.mulesoft.org/schema/mule/munit" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" version="EE-3.7.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/munit http://www.mulesoft.org/schema/mule/munit/current/mule-munit.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsdhttp://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd"><munit:config name="munit" doc:name="MUnit configuration"/><spring:beans>

<spring:import resource="classpath:munit2.xml"/></spring:beans><munit:test name="munit2-test-suite-munit2FlowTest" description="Test">

<flow-ref name="munit2Flow" doc:name="Flow-ref to munit2Flow"/></munit:test>

</mule>* https://developer.mulesoft.com/docs/display/current/Using+MUnit+in+Anypoint+Studio

Creating a Test Via the Wizard

The wizard allows you to create a test for any flow or application in your Studio workspace.

To create a test via the wizard, go to File -> New -> MUnit Test. Now Studio displays the MUnit test creation wizard.

As you can see, the wizard allows you to select any of the flows and applications in the workspace.

If you want to create a test that does not reference a specific flow, click the Create empty test checkbox.

* https://developer.mulesoft.com/docs/display/current/Using+MUnit+in+Anypoint+Studio

Configuring Your Test

Studio displays the newly-created test suite in its own canvas. Here you can tailor your test suite using the Studio interface, just like a regular application. The Studio Palette displays two new sections: MUnit and MUnit Integration Test Tools. To quickly see all MUnit message processors, type munit in the Palette search filter.

* https://developer.mulesoft.com/docs/display/current/Using+MUnit+in+Anypoint+Studio

Running Your TestRunning a Test Suite

To run a test suite, right-click the empty canvas where the suite resides, then select Run MUnit suite. Studio displays the output from the running suite in the console.

Running a TestTo run a test, right-click the name of the test, then select Run MUnit Test.

To check that the test is actually running, view the output in the console. In order not to overwhelm the user, the default output provides little information, but enough to verify that the test has run.

An alternative way to run a test is to use the MUnit tab.1. Select the desired test in the MUnit tab.2. Right-click the test, then select Run.* https://developer.mulesoft.com/docs/display/current/Using+MUnit+in+Anypoint+Studio

Viewing Test ResultsStudio displays MUnit test results in the MUnit tab of the left-hand explorer pane. The MUnit tab displays successful tests in green, failed tests in red.

The Coverage button allows you to see what flow the test covered, and the percentage of message processors in the flow that was covered by the test.

If you run more than one test, the MUnit tab displays a history of run tests. For failed tests, the Errors button displays the stack trace, which you can copy to your clipboard. To copy the stacktrace, right-click the name of the failed test, then select Copy Stack Trace.

As you can see in the image above, you can also use the MUnit tab to run or debug your test, by selecting the appropriate menu option.

Clicking the debug button or the play button on the top right causes the last run or debug to be re-run. This re-run includes all tests that were run on the previous run. You can also select a single test from the previous run to re-run on its own.

* https://developer.mulesoft.com/docs/display/current/Using+MUnit+in+Anypoint+Studio

Debugging TestsYou can debug MUnit tests just like Studio applications, using Studio's debugging perspective.

To access the debugging perspective, click Mule Debug on the top right of the Studio toolbar. This takes you away from the default Mule Design perspective to the debugging perspective, which displays debugging controls.

As with Mule applications, you can mark an MUnit message processor as a breakpoint, where a debug run should stop to enable you to see the information that reaches the message processor.

To debug a test, you can:

– Right-click the test in the canvas, then select Debug MUnit test.

– If you are working in the MUnit tab, you can select a test that previously ran, then click the debug icon on the top right.

– Or right-click the desired test, then select Debug.

* https://developer.mulesoft.com/docs/display/current/Using+MUnit+in+Anypoint+Studio

The End