Unit Testing Using JUnit
JUnit is a unit testing framework for the Java programming language. It is an instance of the xUnit architecture for unit testing frameworks. TIBCO BusinessEvents uses BEUnit (a JUnit based extension) to author unit tests for BusinessEvents applications.
JUnit Use Cases
In BusinessEvents, individual changes in business logic and data could also affect functioning of the BusinessEvents application. Using a unit testing framework, you can better understand the effect of individual changes to the BusinessEvents application.
For example, during migration to a new TIBCO BusinessEvents version, you can use the unit testing framework to test if your old application performs as expected in the new version of the TIBCO BusinessEvents software.
You can refer the BEUnitTest example located at BE_HOME\examples\standard\BEUnitTest\BEUnitTest
for more information.
If you are using a BEUnit project that is migrated from previous TIBCO BusinessEvents version, you must add the property <pathelement path="../../../../lib/ext/tpcl/apache" />
to the build.xml
file of the project. This helps to print appropriate logs when you run the BEUnit project using Apache Ant.
BEUnit (JUnit Extension) Implementation
The BEUnit test framework provides helper classes to author standard JUnit test suites, which you can invoke in the context of a running BE engine.
The following classes are the major classes for the BEUnit test framework:
com.tibco.cep.runtime.service.tester.beunit.BETestEngine
- This class is used for setting up and configuring the BusinessEvents engine to run in a tester context. The BETestEngine class provides methods to assert data into the running test engine, invoke functions, reset the session between tests, and so on.com.tibco.cep.runtime.service.tester.beunit.TestDataHelper
- This class provides helper methods to work with the test data. The existing test data files from previous versions of BusinessEvents can be used in BEUnit tests. You can also create individual concepts and events using the methods available in the TestDataHelper class.com.tibco.cep.runtime.service.tester.beunit.Expecter
- This class provides a comprehensive set of methods to introspect the results of a test run.com.tibco.cep.runtime.service.tester.beunit.ExpectationType
- This Enum class provides a set of fields that identifies the expected result of the test run. This class is used with the Expecter class in BEUnit test suites.
For more information on these classes, refer to Java API Reference.
Unit Test Suite Flow
The general flow of a particular unit test suite is as follows:
- The BETestEngine is configured and the test engine is started. This is performed during the setup phase of the test suite.
- One or more individual unit tests are run against a particular BusinessEvents application as specified in the setup.
- For each individual unit test, the test creates and assert some concepts/events.
- Next, use an Expecter class method to specify a particular outcome. This can include the case such as, determining that a particular rule fired, determining that a concept has been modified, or testing whether an event has been asserted. The Expecter class is used to test the specific behavior of the BusinessEvents application. If the expectation fails (for instance, RuleB fired before RuleA for certain input) the unit test also fails.
You can reset the tester session at any time; however, it is a good practice to do it at the start of an individual test. Resetting the session clears the working memory, and resets any active timers. So, any objects that were asserted in previous tests do not have an effect on the current test.