MUNIT
RUN AND WAIT SCOPE
Shanky Gupta
FUNCTIONALITY
The Run and Wait scope provided by MUnit allows you to instruct
MUnit to wait until all asynchronous executions have completed.
Hence, test execution does not start until all threads opened by
production code have finished processing.
DEFINING RUN AND WAIT
In some cases, your production code may launch threads that produce key
results. Usually, these are the results that you want to validate. But if those
results are being processed in a separate thread, your test runs and finishes
before that separate thread completes, that is, before the results that you
want to validate are available. To avoid this problem, you can use the run-
and-wait scope.
For the purposes of this presentation, we assume that we are testing the
Mule code in following slides:
Visual Editor view
XML code
The goal is to make your test wait until the exampleFlow has finished.
To do so, implement the test as shown below.
1. Define run-and-wait scope.
2. Call the actual production code to test.
DEFINING RUN AND WAIT WITH
JAVA CODE
Java API usage
To define the run-and-wait scope in Java, you need to
implement the Synchronizer abstract class, as shown in the
next slide:
MUnit run and wait scope

MUnit run and wait scope

  • 1.
    MUNIT RUN AND WAITSCOPE Shanky Gupta
  • 2.
    FUNCTIONALITY The Run andWait scope provided by MUnit allows you to instruct MUnit to wait until all asynchronous executions have completed. Hence, test execution does not start until all threads opened by production code have finished processing.
  • 3.
    DEFINING RUN ANDWAIT In some cases, your production code may launch threads that produce key results. Usually, these are the results that you want to validate. But if those results are being processed in a separate thread, your test runs and finishes before that separate thread completes, that is, before the results that you want to validate are available. To avoid this problem, you can use the run- and-wait scope. For the purposes of this presentation, we assume that we are testing the Mule code in following slides:
  • 4.
  • 6.
    The goal isto make your test wait until the exampleFlow has finished. To do so, implement the test as shown below.
  • 7.
    1. Define run-and-waitscope. 2. Call the actual production code to test.
  • 8.
    DEFINING RUN ANDWAIT WITH JAVA CODE Java API usage To define the run-and-wait scope in Java, you need to implement the Synchronizer abstract class, as shown in the next slide: