MetaBoss
User Guides
Synopsis
Beginner's Guide
Configuration Guide
Design Studio Guide
Programming Model Guide
Testing Framework Guide
'How To ...' Guides
References
Synopsis
Design Model Reference
Design Model UML Profile
Test Schema Reference
MetaBoss design library
Run-time libraries API
Dev-time libraries API
HatMaker Example
Synopsis
Enterprise Model Description
Enterprise Model Reference
SystemTest Example
WebServices Example
Miscellaneous
About MetaBoss
Quality Assurance
Compatibility Notes
Acknowledgments
Glossary
Change Log
Version 1.4.0001
Built on 15 Dec 2005 22:31:47

MetaBoss Testing Framework Guide.

System Testing.

Index

Overview
Use of Special XML Elements to create dynamic test cases
Use of XSL Templates to create dynamic test cases
Test Case File Contents Description


Overview

A system test is used to answer questions like "Does system behaviour corresponds to expected behaviour documented in use cases and system design documentation ?" and, if it does not, then "What are the differences between expected and actual outcomes ?". In order to fulfill its purpose the system test needs to be able to execute services with wide variety of different input parameter sets and compare outputs against expected outcomes.

System Test diagram

The picture above shows what happens during the run of system test. In more detail:

  1. XML files with Test Case definitions are read, parsed and executed one by one. These XML files contain definitions of which system needs to be called and what input parameters must be used. They also contain precondition definitions which may be used to exclude certain Test Cases from running if certain condition has been detected. We will look at the content of the Test Case files in more details in the separate chapter below.
  2. Comprehensive log file is being saved with every bit of detail about services being executed. It includes things like services, their inputs, outputs, results of various condition checking, performance data and more.

Some definitions:

  • Test Case - is a XML Element defining a particular transaction, which consists of one or more service invocations and possibly some conditions checking expressions. A Test Case Element is recursive and allows one Test Case to contain one or more smaller Test Cases inside. Test Case element may also contain "dynamic" references to other Test Cases. These references are defined using XSLT and XPath notation. These references are very important tool used to dynamically connect service invocations together - that is use results of previous service invocation as an input to the subsequent service invocations.
  • Test Case File - is an XML file containing one or more TestCases.
  • Test Scenario - is a sequence of Test Cases defined in one or more Test Case Files, which is executed "as one".
  • Test Log File - is a XML file containing details about a single Test Scenario execution. It contains explicit historical information about what has happened (as opposed to Test Case File which contains XSLT and XPath expressions and is is essentally a program).
  • Test Engine (or Test Runner) - is a Java application which reads Test Scenario, executes it and writes the Test Log. At the moment only command line version of the Test Runner is supplied with MetaBoss in ${metaboss_home}/lib/MetaBossSystemTester.jar (the main class is com.metaboss.sdlctools.applications.systemtester.ScenarioRunner). This is enough to run automatic unattended tests from within Ant scripts as well as to perform unit testing and even debugging of the service implementations. In the future releases we are planning to introduce the Interactive GUI version of the Test Runner.

Considering that typical enterprise service impacts the data stored on database, one of the first decisions in preparation of Test Scenarios is the decision what will be the content of the database at the starting point for the test scenario. The choices and their characteristics are:

  • Start with empty database. This choice requires that early Test Cases in the test scenario (or alternatively the database scripts executed before the Test Scenario) populate database with some known data which then can be used by latter Test Cases. The benefit of this approach is the simplicity of writing Test Cases. This is because the database is always in the known state, so many input values can be specified as constants, which is simpler than dynamic values specified with XSLT. The disadvantage of this approach is that it requires services which are able to populate the database (i.e. CRUD or Administration type services or scripts). These facilities may not always be available or accessible. The other disadvantage is that running of tests under this scenario requires cleaning up of existing contents from the database and acquiring exclusive use of database.
  • Start with database with any contents. This choice requires that all Test Cases be smart enough to account for any possible contents found in database and possible even make use of these contents. The benefit of this approach is that Test Scenario can be run on any database (in fact query only Test Scenarios can even be run on production systems to verify their health) and the exclusive use of database is not required. The major drawback is that the Test Cases themselves tend to be more complex as they have to cater for wider range of possibilities.

In practice the approach is usually a mixture of two choices presented above. The choice is even more complex in multisystem Test Scenarios with a number of systems and/or databases to consider. We favour the empty database approach due to its simplicity and outcome predictability. This approach, as we will see later, also makes it possible to reuse same Test Case Fiels in the regression testing.

Use of Special XML Elements to create dynamic test cases

One of the powerful features of the MetaBoss Testing Framework is the ability to use dynamic rendering of the Test Cases based on some dynamic values. The dynamic values are the values not known at the Test Case design time, such as:

  • The current date or time related value. For example the Birth Registry System for Delivery Ward at the hospital might be designed to reject the Date Of Birth values older than two days. The Test Case for such system must be able to come up with the valid Date Of Birth value every time it runs.
  • The environment property related value. This kind of dynamic value may be used to define test execution path or test data values at the test run time rather that at the test design time.
  • The value derived from the results of running previous Test Cases. This type of dynamic value is probably used most often. Ability to have these values is the foundation of the Test Scenario mechanism, which allows to chain Test Cases in sequences with results of previous Test Cases able to be used in the subsequent ones.
  • The value stored in the external data file.

The Special XML Elements dynamic rendering mechanism works as follows:

  1. The Test Engine reads Test Cases, interprets them and invokes services.
  2. At the same time comprehensive Test Log File (also in XML) is being contineously written. It contains information from original Test Cases as well as outputs obtained from the service calls and results of checking these outputs. So, at any point in time the Test Log document contains information about everything what has occurred so far in the test run.
  3. When the Test Engine discovers an embedded Special XML Element inside the Test Case it performs action dictated by this element and uses the resulting value (if any) as if it was read from the original Test Case instead of the Special XML Element. In other words certain portions of the definition of the Test Case to be executed in the next step can be dynamically derived with help of these Special XML Elements.

Following Special XML Elements are currently supported:

  • <ValueOf> This element is replaced with the value of environment property or result of XPath search through the Test Log accumulated up to the point when this element is processed (actual action depends on which attribute is specified inside this element). When it defines the XPath expression search - it actually works similar to the XSL Templates mechanism (described below in this gude) but it is much simpler to write.
  • <ValueOfTimestamp> This element is replaced with the value of current time formatted as per format specification contained in its format attribute. It also offers facility to adjust the current time by specified number of days, minutes etc.
  • <Include> This element is replaced with the content of the file specified in its filename attribute. The included file must be a valid XML file.

Use of XSL Templates to create dynamic test cases

As it was mentioned earlier, one of the powerful features of the MetaBoss Testing Framework is the ability to use dynamic rendering of the Test Cases based on some dynamic values. Previous chapter described how this can be done with use of special XML elements. This chapter will describe how similar outcome can be achieved with use of XSL Templates (XSL stands for eXtensible Stylesheet Language). Note that both methods (XSL Templates and special XML elements) are not mutually exclusive and their set of featues is not the same (there is some overlap though). The XSL Templates can be used to:

  • Define series of service calls based on the series of input data sets.
  • Define parts or whole of input data to the service call as a function of outputs obtained from the preceeding service call.
  • Dynamically decide whether to execute a particular test case based on what happened in the test run prior to the decision making moment
  • Dynamically validate the output from the service call and mark the test case as failed or succeeded.

The XSL Template dynamic rendering mechanism works as follows:

  1. The Test Engine reads Test Cases, interprets them and invokes services.
  2. At the same time comprehensive Test Log File (also in XML) is being contineously written. It contains information from original Test Cases as well as outputs obtained from the service calls and results of checking these outputs. So, at any point in time the Test Log document contains information about everything what has occurred so far in the test run.
  3. When the Test Engine discovers an embedded XSL Template inside the Test Case it performs transformation of the Test Log with use of this XSL Template and uses the resulting XML document as if it was read from the original Test Case instead of the XSL Template. In other words any portion of the Test Case to be executed in the next step can be dynamically derived from the Test Log containing everything what has happened in all previous steps.

Test Case File Contents Description

The role of the Test Case File is to define execution sequence of operations, inputs to these operations and checks to be performed on the outputs from these operations.

The syntax inside Test Case Files is controlled by the Test Schema. The current and past versions of the Test Schema definitions can be found here. Some examples of Test Case Files can be found here.

The root element of the file is the TestCasePlan element. This element can be used recursively meaning that TestCasePlan elements can be owned by the other TestCasePlan element. This feature forms the basis for creating a tree like formations of Test Cases. Test cases are executed in sequence as they appear in file (In other words the tree of test cases is flattened and than executed). The failure of any given test case will not automatically preclude execution of all other test cases regardless of their position (eg. sibling test case, child test case etc.) However, when outcome of any test case execution is reported in the log - it is set to the worst outcome of any of its descendants. This means that the outcome of the root (or the topmost) test case element always reflects the full story and if it says "Success" that means that each and every descendant test case execution has succeeded. TestCasePlan has a number of special attributes:

  • sleepBefore This attribute, if given, forces the Test Engine to pause test execution prior to running of this TestCase for a specified number of seconds. It can be used to introduce some delays required for testing of a time sensitive scenarios.

  • sleepAfter This attribute, if given, forces the Test Engine to pause test execution after running of this TestCase for a specified number of seconds. It can be used to introduce some delays required for testing of a time sensitive scenarios.

  • numberOfRuns This optional attribute contains positive numeric value ( >= 1) which defines how many times the test case should be run. By default the test case is run once. Note that the next run of the test will only be attempted if the previous run has been successfull. This atttribute can be used to create repetitive scenarios for load testing. During repetitive execution the separate TestLogElement is created for every run and the special 'runNumber' attribute which contains the number of the run is set in it.

The TestCasePlan element may contain following sub elements:

  • First element inside TestCasePlan element is the PrerequisiteDocument. This optional element controls whether owner Test Case (ie. the TestCase which owns this PrerequisiteDocument) and all Test Cases owned by it will be executed. If this element is absent, the TestCase is considered to be OK to execute. The PrerequisiteDocument element in the TestCasePlan usually contains the XSL Template. The fully rendered form of this document (ie. after all templates are applied) in the TestCaseLog may contain any number of ErrorMessage, WarningMessage or InformationMessage elements. These elements are simple containers for the text messages describing a particular condition. They will appear in the Test Scenario Log and should help to explain the grounds on which the decision was made. The Test Engine also looks at these messages. If, after rendering all templates, the Test Engine discovers one or more ErrorMessage elements it will skip the execution of the owner Test Case and all sub TestCases. The next Test Case the Test Engine will look at is the next sibling of the owner Test Case. To summarise, PrerequisiteDocument allows to check anything in the Test Scenario Log, decide whether prerequisite conditions for execution of the TestCase branch have been met and subsequently approove or veto the execution of the Test Case.

  • The next element is the ParametersDocument. This optional element may be used to keep parameters of the test organised and visible. It may contain any number of XML elements of any kind organised in any kind of hierarchy. The typical use of the ParametersDocument would be to design the ParametersDocument layout suitable to contain the test input data in simple and easy to understand hierarchy and than to develop a XSL Template, which renders actual Test Cases based on the contents of this ParametersDocument. ParametersDocument element may also contain an Include element, which allows to dynamically insert contents of the external XML file.

  • The next element could be one of:
    • One only OperationPlan element. OperationPlan is the element which contains input structure to the desired operation. It may be defined explicitly or via template.
    • One or more child TestCasePlan elements.
    • One only Template element. This element contains the XSL Template which is expected to render single OperationPlan element or any number of child Test Cases.
  • The last element is the AcceptanceDocument. This optional element controls whether owner Test Case (ie. the TestCase which owns this AcceptanceDocument) is deemed to have succeeded or failed. If this element is absent, the Test Case is automatically marked as failed if operation has failed (indicated by IsSuccessful element inside every operation result document), exception has been thrown while this TestCase was executing or ,if this is a composite Test Case, when one of the child test cases has failed. The AcceptanceDocument element in the TestCasePlan usually contains the XSL Template. The fully rendered form of this element (ie. after all templates are applied) in the TestCaseLog may contain any number of ErrorMessage, WarningMessage, InformationMessage or AcceptanceMessage elements. These elements are simple containers for the text messages describing a particular condition. They will appear in the Test Scenario Log and should help to explain the grounds on which the decision was made. The Test Engine also looks at these messages. If, after rendering all templates, the Test Engine discovers one or more ErrorMessage elements it will mark the owner Test Case as failed even though it has not thrown any exceptions. On the other hand if Test Engine discovers one or more AcceptanceMessage elements it will mark the owner Test Case as succeeded even though it may have thrown the exception. To summarise, AcceptanceDocument allows to check anything in the Test Scenario Log and decide whether the Test Case which owns this element have succeeeded or failed and mark the Test Case accordingly.

The TestCasePlan, OperationPlan and ParametersDocument elements offer a number of common attributes designed to help with documenting and identification of certain areas in the Test Scenario. During execution of the scenario these attributes are copied to the corresponding TestCaseLog, OperationLog and ParametersDocument elements in the Test Log. The attributes and their descriptions are:

  • name This attribute can contain any non-unique name (meaning that more than one element in the whole scenario may have exactly the same name). Name can of course be used for naming certain elements to improve readability. It also may be used to find group of elements via simple XPath expression. For example expression '//OperationLog[@name='mytest']' may be used to select all operations with the name 'mytest'.

  • id This attribute can contain any value, but the value must be unique. This means that one and only one element, regardless of its type, can have a particular Id. The Test Engine will ensure this uniqueness by keeping track of these ids and failing test run when duplicate id is discovered. Id may be used to find a particular element via simple XPath expression. For example expression '//*[@id='mytest5']' may be used to select a single element with the id 'mytest5'.

  • description This attribute is a simple description of the owner element. It can be used for naming certain elements to improve readability.