Open topic with navigation

TIBCO BusinessEvents® Enterprise Edition 6.3.1

# 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.

Note: 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 BusinessEvents 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:

1. The BETestEngine is configured and the test engine is started. This is performed during the setup phase of the test suite.
2. One or more individual unit tests are run against a particular BusinessEvents application as specified in the setup.
3. For each individual unit test, the test creates and assert some concepts/events.
4. 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.

Subtopics

Did you find this helpful?

YesNo
Great!
Thanks for taking the time to give us some feedback.
Sorry about that

Why wasn't this helpful? (check all that apply)

Could not find what I was looking for
Instructions confusing or unclear
Instructions did not work

Want to tell us more?

Please select at least one option or provide details about the issue!!

Error occurred while submitting feedback.

Error2 occurred while submitting feedback.

TIBCO BusinessEvents® Enterprise Edition

Copyright © 2004-2024. Cloud Software Group, Inc. All Rights Reserved.