Editing EventFlow Fragment Unit Tests

Overview

Java test files generated by the StreamBase JUnit wizard are incomplete and must be edited to become a useful test. This topic provides guidelines for completing the edit of your generated EventFlow Fragment Unit Test files.

File Contents

A generated unit test file includes:

  • One example tuple using generated test data for one input stream of the module to be tested.

  • An Expecter object that defines a tuple for each of the module's output ports.

Using Non-Default Container Names in Tests

The generated unit test file includes a loadApp() line like the following example. This line is responsible for loading the specified application module into the test StreamBase Server.

server.loadApp("appname.sbapp");

The line as generated loads the named module into a container named default. In this case, the StreamBase paths to the names of streams in your test code can be simple names without a container name, because StreamBase presumes a container named default if you do not specify a container. Thus, for a test of the Best Bids and Asks sample included with StreamBase, when using the default container, the following test code fragments are valid:

server.getEnqueuer("NYSE_Feed").enqueue( ...
...
new Expecter(server.getDequeuer("BestAsks"))

You may have an application-specific reason to load your test module into a container other than default. To do this in your test code, add a container name as a second argument to the loadApp method, like the following example:

server.loadApp("appname.sbapp", "testcontainer");

The

server.loadApp("appname.sbapp", "testcontainer");

method may be called multiple times to prepare multiple container applications for the tests.

In this case, you must make sure that all StreamBase paths in the test file include the container name. For example:

server.getEnqueuer("testcontainer.NYSE_Feed").enqueue( ...
...
new Expecter(server.getDequeuer("testcontainer.BestAsks"))

Further Options

You are not limited to the code generated by the wizard. For example, you might prefer to enqueue your input tuples constructed with ObjectArrayTupleMaker.MAKER instead of JSONSingleQuotesTupleMaker.MAKER.

If you need your test to reset the state of the module under test in preparation for further tests, your test code can include a passage like the following:

stopContainers(); startContainers();

Use the Javadoc documentation for the com.streambase.sb.unittest package as a guide to the test features available. See Java API Documentation.

Back to Top ^