2. What is Testing
Test Flavors
Test Tooling
what is Munit and what are its uses in Relattion to Mule
What Test Driven Development and how it helps
M U N I T i n M u l e
3. What is Testing
In general, testing is finding out how well something works.
In terms of human beings, testing tells what level of knowledge or skill
has been acquired.
In computer hardware and software development, testing is used at key
checkpoints in the overall process to determine whether objectives are
being met.
For example, in software development, product objectives are sometimes
tested by product user representatives.
When the design is complete, coding follows and the finished code is
then tested at the unit or module level by each programmer;
at the component level by the group of programmers involved; and at
the system level when all components are combined together.
At early or late stages, a product or service may also be tested
for usability.
4. Testing Flavors
Unit tests
Tests 'units' of work
Fast, no external systems, always returns the same result
Considered portable, any developer can run them
Integration tests
Tests interactions between components.
Often using external resources in test, typically mocked in a unit test
Functional tests
Tests the functional requirement(s) of the application
Testing Benefits
Iterate comfortably
Tests act as descriptors of application-interaction
Fast root cause analysis
Less time debugging
Confidence in your work
5. Tools available for doing the Unit Test
Junit
Most used Java framework to write repeatable tests
Requires a mocking framework such as Mockito to perform unit tests
• Munit
Mule testing framework
Rich feature set built in, including mocking
Written in XML or Java
We'll be focusing on MUnit in this module; test cases written in MUnit and
Junit
can be included in your builds
6. Test Driven Development - TDD
1. Write a test
2. Run the test and verify it fails
3. Write the smallest / simplest solution to make the test pass
4. Re-run the test and verify it passes
5. Look for refactoring opportunities
Pros
Naturally creates a regression test suite
Resolving tests can bring visibility to subtle design
patterns
Less risk of (accidentally) changing functionality or
introducing bugs
Becomes inherent in the build life cycle
Developers ensure they don't break other features in
the project
Cons
Requires additional upfront time
Mule's abstraction can challenge purist TDD guidelines
Requires a buy in with engineering
7. MUnit libraries are available within MuleSoft
If Studio is doing POM maintenance for you, this dependency and others are
take care of
• Part of releases
• Placed as a test scope within Maven dependencies
• Package: org.mule.munit
• Artifact: munit
<dependency>
<groupId>org.mule.munit</groupId>
<artifactId>munit</artifactId>
<version>${munit.version}</version>
<scope>test</scope>
</dependency>
<plugin>
<groupId>org.mule.munit.tools</groupId>
<artifactId>munit-maven-plugin</artifactId>
<version>${munit.version}</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>Example Munit Test Case :
8. munit:config is expected for each test case
<munit:config/>
– Defines behavior of connectors and endpoints
• Spring is used to import configuration(s)
<spring:beans>
<spring:importresource="order6provisioning.xml"/>
<spring:importresource="order6retrieval.xml"/>
</spring:beans>
A truth about returned result(s) or execution context
• Expressive configuration using MEL
• Custom (Java) assertions supported
• Similar to assertions in *Unit frameworks
<munit:assert-truecondition="#[payloadisjava.util.Map]"/>
<munit:assert-on-equalsexpectedValue="#[string:'Hello']"
actualValue="#[payload.toString()]"/>
<munit:assert-falsecondition="#[payload.length=0]"/>
<munit:assert-not-null/>
<munit:assert-not-sameexpectedValue='#[string:]‘actualValue='#[payload]'/>