The code and files on this page support the following paper submission:
Escott, E., Strooper, P., Steel, J., and King, P.: Integrating Model-Based Testing in Model-Driven Web Engineering, The 18th Asia-Pacific Software Engineering Conference (APSEC 2011).
Purpose
The purpose of the test script generator is to produce concrete test cases directly from a UML model. The test script generator uses requirements-based criteria to reason about what test cases must be generated, i.e., we can focus our tests on each of the individual requirements in CRUD.
Files
These are the files used and generated by the test script generator. The code files were hand-written in Java. The generated files are XML test cases used to gain code coverage metrics of the target application. In addition, code snippets from the JUnit driver are presented.
Code
The generation process is a multi-stage process. The first step programmatically queries the UML model and creates instances of an XMLbean. The XML is subsequently passed to a JET template that is responsible for the test case generation.
| TestScriptsImpl.java | This is the main driver for the test script generator. The method generateXML is the entry point and is passed the model via the parameters. |
| TestScriptsUtil.java | Utility class to help with generic xmlbean code. |
| BaseChoiceData.java | Wrapper for base choice data. Calculates a base choice given the constructors arguments. |
| AssociationData.java | Wrapper for association data. The entity being tested mst have their assocations populated as well. |
| TestCaseData.java | Wrapper for test case data. Used to encapsulate data for easier passing between methods. |
| testscripts.xsd | The XSD that defines what a test case will look like. This is compiled using XMLbeans. |
| testcase.xml.jet | The JET template used to generate the test cases. The template will be invoked for each test case. |
Generated
These are the XML files generated from the test script generator. These XML files are used as input to the JUnit tests described below.
| ProductCreateSave001.xml | Start at the list page, click the new button, input form values, click the save button |
| ProductCreateCancel001.xml | Start at the list page, click the new button, input correct form values, click the cancel button |
| ProductCreateValidation001.xml | Start at the list page, click the new button, input incorrect form values, click the save button |
| ProductCreateValidation002.xml | Start at the list page, click the new button, input incorrect form values, click the save button |
| ProductCreateValidation003.xml | Start at the list page, click the new button, input incorrect form values, click the save button |
| ProductReadSelected001.xml | Start at the list page, select an entity, click the view button |
| ProductReadNotSelected001.xml | Start at the list page, do not select an entity, click the view button |
| ProductUpdateSave001.xml | Start at the list page, select an entity, click the update button, change form values, click the save button |
| ProductUpdateCancel001.xml | Start at the list page, select an entity, click the update button, change to correct form values, click the cancel button |
| ProductUpdateNotSelected001.xml | Start at the list page, do not select an entity, click the update button |
| ProductUpdateValidation001.xml | Start at the list page, select an entity, click the update button, change to incorrect form values, click the save button |
| ProductUpdateValidation002.xml | Start at the list page, select an entity, click the update button, change to incorrect form values, click the save button |
| ProductUpdateValidation003.xml | Start at the list page, select an entity, click the update button, change to incorrect form values, click the save button |
| ProductDeleteOk001.xml | Start at the list page, select an entity, click the delete button, click the ok button |
| ProductDeleteNotSelected001.xml | Start at the list page, do not select an entity, click the delete button |
| ProductDeleteCancel001.xml | Start at the list page, select an entity, click the delete button, click the cancel button |
JUnit
These code snippets are supplied as an overview how JUnit is used. In the first code snippet, the test suite is create by looping through the XML files creating a new JUnit test case for each file. In the second code snippet, the actual test case is run using the XML is setup, input, and expected of the test case.
public class AllTests {
private static String[] productOnMethods = {"CreateSave", "CreateValidation", "CreateCancel", "ReadSelected",
"ReadNotSelected", "UpdateSave", "UpdateValidation", "UpdateCancel",
"UpdateNotSelected", "DeleteOk", "DeleteCancel", "DeleteNotSelected"};
...
/**
* Create the test suite.
*/
public static Test suite() {
TestSuite suite = new TestSuite("StickersRock System Test Suite");
/*
* Wrapper for test suite tearDown
*/
TestSetup wrapper = new TestSetup(suite) {
protected void tearDown() throws Exception {
oneTimeTearDown();
}
};
try {
startJetty();
} catch (Exception e) {
e.printStackTrace();
}
for(String onMethod: productOnMethods) {
boolean moreFiles = true;
int count = 1;
while(moreFiles) {
String countString = getCountString(count);
count++;
String xmlFilename = dir + "product/Product" + onMethod + countString + ".xml";
File file = new File(xmlFilename);
if(file.exists()) {
ProductTest test = new ProductTest("test" + onMethod, file, server);
suite.addTest(test);
} else {
moreFiles = false;
}
}
}
return wrapper;
}
...
}
public class ProductTest extends SystemTestCase {
public ProductTest() {
super();
}
public ProductTest(String name, File file, Server server) {
super(name, file, server);
}
@Override
protected void setUp() throws Exception {
super.setUp();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
public void testCreateSave() throws Exception {
webTester.beginAt("/ProductList.html");
webTester.clickButtonWithText("New");
boolean clickAdd = doHtmlInput();
if(clickAdd) {
webTester.clickButtonWithText("Add ->");
}
webTester.clickButtonWithText("Save");
checkExpected();
}
...
}
