The LSPS Application contains the testing project with sample JUnit tests.
The API is provided by the packages in com.whitestein.lsps.test.
The API for web tests (clicker GUI tests) is provided in the com.whitestein.lsps.test.web packages
Important: To use the API of com.whitestein.lsps.test.web, purchase the Vaadin TestBench license.
For detailed documentation, refer to the Javadoc documentation in the documentation/apidocs directory in Designer or the Javadoc online documentation.
The LSPS Application provides API for testing of modules as well as for clicker tests of the GUI and forms, both ui and forms.
The generated LSPS Application comes with example JUnit tests SampleModelIT.java
, with a test class that uploads a model, creates its instance and evaluates an expression in the context of the model instance
To create your own JUnit test, do the following:
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:
src/test/java
:LspsRemote
methods.public class MyTestsIT { private LspsRemote remote; private String moduleName; private File moduleFile; private Module module; @Before public void lspsRemote() { remote = LspsRemote.ADMIN; //create("admin", "admin", "http://localhost:8080"); moduleName = "myTestModule"; moduleFile = new File("src/modules").getAbsoluteFile(); //Since uploadModule is an expensive operation, //we check if the module are uploaded already before upload: ModuleCriteria criteria = new ModuleCriteria(); criteria.setNamePattern(moduleName); if (remote.findModules(criteria).isEmpty()) { remote.unloadAllModules(); module = remote.uploadModule(moduleName, "1.0", moduleFile); } else { module = remote.getLatestModule(moduleName); } } @Test public void myTestNoUI() throws Exception { ModelInstance mi = module.startModelInstance(); String logMessage = mi.getLogs().get(0).getDescription(); assertTrue(logMessage.equals("My message")); } }
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:
The generated LSPS Application comes with example JUnit tests for both implementations of forms in the tester project:
SampleUIIT.java
: a sample test class that tests the UI formSampleFormsIT.java
: a sample test class that test the Forms formsBefore creating and running your clicker tests to test the GUI and forms in the LSPS Process Application, do the following:
c:\Users\<USERNAME>\
).Enable the modeling IDs so you can identify form components by their modeling ID on runtime: run the LSPS Server with the -Dcom.whitestein.lsps.vaadin.ui.debug=true
property.
To add the property to the SDK Embedded Server, in the Java perspective of Designer, go to Run > Run Configurations; select the configuration under Java Application and add the property on the Arguments tab to Program Arguments).
To create your own JUnit test, do the following:
<YOUR_APP>/tester
. testbench_chromedriver
property with the path to the ChromeDriver.src/test/java
.testbench_firefox
property set to the path to your Firefox, for example, -Dtestbench_firefox="C:\Users\John\Firefox_46\"
LspsRemote
methods.To get a form component, use of the following methods on the application tester (IUDefaultAppTester) to search in the entire form tree or on a component to search in the component subtree:
findByLspsId()
with the ID of the component you set in the ID propertyfindByFormId()
with the modeling ID of the componentfindById()
with the HTML ID of the component: This is identical to the modeling id assuming the component is rendered only once.Mind that the methods return a UIComponent object: to cast it to a component type, call the as()
method; for example, app.findByLspsId("my_vl").as().verticalLayout();
To work with the content inserted by a reusable form component, get the root of the tree with the findByFormId()
method on the application helper class.
@Test public void findFormComponentByID() { remote().uploadModule("module", "1.0", PATH_TO_MODEL); app.loginAndWait("admin", "admin"); app.openDocument("My Document"); //passing the modeling id of the Reusable Form component //defined in the calling form: assertNotNull(app.findByFormId("child__PrCxYARREemLruQ6nAkFiw")); }
If you plan to run the tests on a remote server, edit the JVM parameters:
-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.To run JUnit tests of a model, do the following:
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
.In Designer, 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
.
-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.