LSPS documentation logo
LSPS Documentation
Tests

The LSPS Server API provides supports for JUnit testing of your models.

The generated LSPS Application contains the testing project with sample JUnit tests with the JUnit API provided by the following packages:

  • com.whitestein.lsps.test: API for model and model instance management, to-do management, and log management
  • com.whitestein.lsps.test.web: Basic class for testing of front-end applications
  • com.whitestein.lsps.test.web.components: API for testing of form components in front-end applications

Important: To be able to use the API of com.whitestein.lsps.test.web and com.whitestein.lsps.test.web.components, purchase the Vaadin TestBench license. Also make sure you use a browser that is compatible with the underlying TestBench version.

For detailed documentation, refer to the Javadoc documentation in the documentation/apidocs directory in PDS or the Javadoc online documentation.

Prerequisites

  1. Before you create tests of the GUI of the LSPS Process Application, do the following (If you don't require such clicker tests, skip this step):

    • Purchase the Vaadin TestBench license and copy the license to your home directory (on Windows to c:\Users\<USERNAME>\).
    • Enable the modeling IDs so you can identify form components on runtime: run the LSPS Server with the -Dcom.whitestein.lsps.vaadin.ui.debug=true property.

    To add the property to SDK Embedded Server, in the Java perspective of PDS, go to Run > Run Configurations; select the configuration under Java Application and add the property on the Arguments tab to VM arguments).

  2. If you plan to run the tests on other than the localhost server with port 8080, edit the JVM parameters:
    1. Go to Run > Run Configurations
    2. Double-click JUnit and create your configuration for the target JUnit class with the JVM arguments -Dselenium.host=<SERVER_IP> and -Dselenium.port=<SERVER_PORT>. Make sure you enabled the modeling IDs, that is, your server is running with the -Dcom.whitestein.lsps.vaadin.ui.debug=true property.
  3. Set up Google Chrome as the testing browser:
    1. Download the ChromeDriver for your OS and copy it to <YOUR_APP>/tester.
    2. In SampleUIIT or Sample, change the UIDefaultAppTester to return ChromeDriver:
      //original content with firefox driver:
      //protected UIDefaultAppTester app = new UIDefaultAppTester(new FirefoxDriver(), VAADIN_APP_CONTEXT_ROOT);
      // modified content with chrome driver:
      protected UIDefaultAppTester app = new UIDefaultAppTester(new ChromeDriver(), VAADIN_APP_CONTEXT_ROOT);
      

Running JUnit Tests

To run JUnit tests of a model, do the following:

  1. Synchronize maven and eclipse (run mvn eclipse:eclipse) and add the artifacts to maven repo (run mvn clean install).
  2. Refresh the GO-BPMN Explorer.
  3. Run or connect PDS to your LSPS Server (typically, you will run SDK Embedded Server with your application using the launcher).
  4. Run the test:
    • In PDS, right-click the tester project or the Java test class, then Run As > JUnit Test.

      Alternatively, on the command line, go to the location of the application tester project and run mvn clean install -Dlsps.tester.

Creating JUnit Tests

To create a JUnit test, do the following:

  1. Open the workspace with the source of the application. In the generated LSPS Application, JUnit testing resources are stored in the <YOUR_APP>-tester project:
    • SampleModelIT.java: a sample test class that uploads a model, creates its instance and evaluates an expression in the context of the model instance
    • SampleUIIT.java: a sample test class that test the UI
    • test.properties: relative path to the tested model and to the Standard Library Modules (Standard Library resources are dependencies of the LSPS test classes)
    • pom.xml: Maven POM file with dependencies

      Since the tests need a running LSPS Server, Maven compilation does not run the tests by default. The pom.xml file therefore defines the lsps.tester parameter, which allows you to run the JUnit tests on compilation:

      mvn clean install -Dlsps.tester
      
      lspsAppGenerated.png
      SampleTest class in the default LSPS Application
  2. Modify or create a new testing class:
    1. Open the application tester project.
    2. Expand the src package and open the SampleModelTests.java or SampleUIIT.java file.

      Note that the testing classes are JUnit 4 tests and hence require annotations, such as @Before. The classes provide multiple LSPS-specific testing methods which are based on the methods of the com.whitestein.lsps.test classes:

      For tests that do not require GUI testing, perform LspsRemote calls. When testing the GUI, create a UITester instance.

    3. Edit the sample test file.

      From tests, you can access only the model context: Data from child contexts, such as Sub-Process variables, are not available for testing.

  3. Edit the test.properties file to point to the location with the project with your model if applicable. Optionally, provide paths to libraries.
  4. If you have modified the pom.xml file or provided paths to custom libraries in test.properties, open a terminal/command line and go to the location of the test project:
    1. synchronize maven and eclipse: run mvn eclipse:eclipse
    2. Re-build the maven artifact to acquire the dependencies: run mvn clean install.
  5. Refresh the GO-BPMN Explorer.

Testing Record Values

When testing record values, consider returning preferably value of simple types from tested expressions.

Instead of:

String patientName = (String) modelInstance.execute(getJohnDoe().name).toObject();
assertEquals("John", patientName);
String patientSurname = (String) modelInstance.execute(getJohnDoe().surname).toObject();

move the logic to the expression:

Boolean arePatientDetailsCorrect = (Boolean) modelInstance.execute(
    "def Patient john := getJohnDoe(); john.name==\"John" and john.surname=="Doe"").toObject();
)
assertEquals(true, arePatientDetailsCorrect)

Alternatively, you can store the returned object as RecordValue:

RecordValue rec = (RecordValue) modelInstance.execute("getMyRecordById(1)").toObject();