Introduction to Unit Testing for Mule Flows using Munit(Java) - Part 1 January 6, 2015
What is a unit test? A unit test is an automated piece of code that invokes a unit of work in the system and then checks a single assumption about the behavior of that unit of work. A unit of work is a single logical functional use case in the system that can be invoked by some public interface (in most cases). A unit of work can span a single method, a whole class or multiple classes working together to achieve one single logical purpose that can be verified.
What makes a good unit test? 1. Able to be fully automated 2. Has full control over all the pieces running (Use mocks or stubs to achieve this isolation when needed) 3. Can be run in any order if part of many other tests 4. Runs in memory (no DB or File access, for example) 5. Consistently returns the same result (You always run the same test, so no random numbers, for example. save those for integration or range tests) 6. Runs fast 7. Tests a single logical concept in the system 8. Readable 9. Maintainable 10.Trustworthy (when you see its result, you don’t need to debug the code just to be sure)
Why do we need a Unit Test? 1. Tests Reduce Bugs in New Features 2. Tests Reduce Bugs in Existing Features 3. Tests Are Good Documentation 4. Tests Reduce the Cost of Change 5. Tests Improve Design 6. Tests Allow Refactoring 7. Tests Constrain Features 8. Tests Defend Against Other Programmers
Dependencies Anypoint Studio (any Runtime) ● Junit ● Munit ● Hamcrest
What is JUnit? JUnit is a simple framework to write repeatable tests. It is an instance of the xUnit architecture for unit testing frameworks.
What is Munit? MUnit is a Mule application testing framework that allows you to easily build automated tests for your integrations and APIs. It provides a full suite of integration and unit test capabilities, and is fully integrated with Maven and Surefire for integration with your continuous deployment environment.
Munit Capabilities 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
Munit Capabilities Verify message processor calls Create 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
Credits http://artofunittesting.com/definition-of-a-unit-test/ http://junit.org/ https://docs.mulesoft.com/mule-user-guide/v/3.7/munit http://www.onjava.com/pub/a/onjava/2003/04/02/javaxpckbk.html

Introduction to Unit Testing for Mule Flows using Munit(Java) - Part 1

  • 1.
    Introduction to UnitTesting for Mule Flows using Munit(Java) - Part 1 January 6, 2015
  • 2.
    What is aunit test? A unit test is an automated piece of code that invokes a unit of work in the system and then checks a single assumption about the behavior of that unit of work. A unit of work is a single logical functional use case in the system that can be invoked by some public interface (in most cases). A unit of work can span a single method, a whole class or multiple classes working together to achieve one single logical purpose that can be verified.
  • 3.
    What makes agood unit test? 1. Able to be fully automated 2. Has full control over all the pieces running (Use mocks or stubs to achieve this isolation when needed) 3. Can be run in any order if part of many other tests 4. Runs in memory (no DB or File access, for example) 5. Consistently returns the same result (You always run the same test, so no random numbers, for example. save those for integration or range tests) 6. Runs fast 7. Tests a single logical concept in the system 8. Readable 9. Maintainable 10.Trustworthy (when you see its result, you don’t need to debug the code just to be sure)
  • 4.
    Why do weneed a Unit Test? 1. Tests Reduce Bugs in New Features 2. Tests Reduce Bugs in Existing Features 3. Tests Are Good Documentation 4. Tests Reduce the Cost of Change 5. Tests Improve Design 6. Tests Allow Refactoring 7. Tests Constrain Features 8. Tests Defend Against Other Programmers
  • 5.
    Dependencies Anypoint Studio (anyRuntime) ● Junit ● Munit ● Hamcrest
  • 6.
    What is JUnit? JUnitis a simple framework to write repeatable tests. It is an instance of the xUnit architecture for unit testing frameworks.
  • 7.
    What is Munit? MUnitis a Mule application testing framework that allows you to easily build automated tests for your integrations and APIs. It provides a full suite of integration and unit test capabilities, and is fully integrated with Maven and Surefire for integration with your continuous deployment environment.
  • 8.
    Munit Capabilities Create yourMule 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
  • 9.
    Munit Capabilities Verify messageprocessor calls Create 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
  • 10.