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:
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.
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):
c:\Users\<USERNAME>\
).-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).
-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.<YOUR_APP>/tester
.//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);
To run JUnit tests of a model, do the following:
mvn eclipse:eclipse
) and add the artifacts to maven repo (run mvn clean install
).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
.
To create a JUnit test, do the following:
<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 instanceSampleUIIT.java
: a sample test class that test the UItest.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
tester
project.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.
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.
test.properties
file to point to the location with the project with your model if applicable. Optionally, provide paths to libraries.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:mvn eclipse:eclipse
mvn clean install
.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();