Tutorial: Test with JUnit

JUnit provides a good framework to manage and execute unit test cases. This tutorial shows you how to write JUnit test case java code to run your model and mCases. We assume that you are already familiar with how to write a JUnit test case java code.

Setup Server Startup

First create a JUnit java class and add a static initializer code below:

    static {
   	try {
	   TestOptimalClient.startTestOptimalServer(new String[]{});
	catch (Exception e) {

The static initializer starts up TestOptimal process and opens your model getting it ready to execute.

Create Test Methods

Next create the test method and in the body of the method add the following script to execute the model.

  TestOptimalClient.executeModel(null, "Execution from JUnit");

The above java code submits the model execution request to TestOptimal process and waits for the execution to complete. Depending on the sequencer you have selected for the model, it will run different test sequences accordingly.

That's it. The JUnit test case is ready to be executed.

Test Results

The test results are automatically saved with the model and can be viewed from Stats Tab. The “Execution from JUnit” is a description to be attached to the test results.

If you have several functional test cases created in the model (mCase), you can execute them all or one by one. The java code below executes the “QuickPurchase” mCase:

  TestOptimalClient.executeModel("QuickPurchase", "Execution from JUnit");