LSPS documentation logo
LSPS Documentation
Model JUnit Tests

This part provides information on how to perform JUnit testing on your models.

Note: This document instructs you to generate the Default LSPS Application and modify the generated sample testing project. The sample testing project is provided for your convenience as part of the Default LSPS Application but you can create your own classes and projects as well. Mind that if you decide to create your own project, you will need to import the jars required by the testing classes, either manually or using maven, create the pom.xml file with the test target, and manually create the test.properties file.

You can create JUnit tests using the API of 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 front-end applications
  • com.whitestein.lsps.test.web.components: API for testing over 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.

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

Prerequisites

Before you work with the testing resources of the LSPS Application, do the following:

  • Enable the modeling IDs so you can identify form components on runtime: make sure your server is running with the -Dcom.whitestein.lsps.vaadin.ui.debug=true property (in PDS, go to Runtime Connection > Runtime Connection Settings; select the connection and click Edit).
  • If you want to create tests of the UI, purchase the Vaadin TestBench 4 license.

Creating JUnit Tests

Note: If you do not want to use the resources generated as part of the Default LSPS Application, you can create them manually: either you import all the dependencies or create a custom pom.xml that will pull them for you. After mvn clean install and run mvn eclipse:eclipse make sure to refresh the GO-BPMN Explorer.

To create a JUnit test in the Application User Interface, do the following:

  1. Open the workspace with the Default LSPS Application.
  2. Open your <APPLICATION>-tester project with the sample test classes:
    • SampleNonUIIT.java: a dummy sample test class that uploads a model, creates its instance and evaluates an expression in the context of the Model instance
    • SampleUIIT.java: a dummy sample test class that tests execution of To-Dos
    • test.properties: relative path to the tested model and to the Standard Library Modules
    • 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
  3. Modify or create a testing class:
    1. Open the application tester project.
    2. Expand the src package and open the SampleNonUIIT.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 from com.whitestein.lsps.test:

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

    3. Edit the sample test file.

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

  4. Edit the test.properties file to point to the location with the project with your model if applicable. Optionally, provide paths to libraries.
  5. 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.
  6. Refresh the GO-BPMN Explorer.

Running JUnit Tests

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

  1. Make sure you have synchronized maven and eclipse (run mvn eclipse:eclipse) and re-build the maven artifact to acquire the dependencies (run mvn clean install) if necessary.
  2. Refresh the GO-BPMN Explorer.
  3. Run your LSPS server (typically the SDK Embedded Server with your application using the launcher).
  4. Run the test:
    • To run the test 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.
    • In PDS, right-click the Java test class and click 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. Make sure you enabled the modeling IDs, that is, your server is running with the -Dcom.whitestein.lsps.vaadin.ui.debug=true property.