Skip to content

The SUT Service

itaiag edited this page Aug 9, 2016 · 1 revision

System Under Test (SUT) Independence

SUT Independence is the ability to run the same test on different setups without changing the test. Every test setup is comprised of a set of “SystemObjects” also known as drivers. One of the framework requirements is that test that was written for one SUT can be executed on a different SUT without changing the test code. All the setup specific information should be placed in the SUT files. The SUT files are XML files that describe the SUT. Every SUT is allocated its own independent SUT file.

What is the SUT

The SUT is the device and or software being tested, as well as they peripheral testing software and hardware that is used to check the DUT. When planning an automation project one of the first steps required is to define the SUT. Potential elements that can be included in the SUT include:

  • Device and or software being tested.

  • Workstations or PC’s that are part of the setup to be managed.

  • A generator of any kind.

  • Dynamic configuration.

How the SUT Service Works

The SUT independent service works in the following manner: when the test author writer requires the use of a system object, the state of the system object is loaded from the SUT file using java reflection.

SUT Code Example

The following code represents a SystemObject code example.

 package com.aqua. services.systemobject;
 
 import jsystem.framework.system.SystemObjectImpl;
 import jsystem.utils.FileUtils;
 
 public class MyDevice extends SystemObjectImpl{
    
     private String message;
     private String fileName;
    
     public void init() throws Exception {
         super.init();
         report.report("Hello world init");
     }
     public void close(){
         report.report("Hello world close");
         super.close();
     }
     public void getHelloMessage() throws Exception {
         report.report("Hello Message",getMessage(),true);
     }
     public void readFromFile() throws Exception {
         String textFromFile = FileUtils.read(getFileName());
         setTestAgainsObject(textFromFile);
     }
     public String getMessage() {
         return message;
     }
     public void setMessage(String message) {
         this.message = message;
     }
     public String getFileName() {
         return fileName;
     }
     public void setFileName(String fileName) {
         this.fileName = fileName;
     }
 }

SUT Test Code Example

This code example shows a test that uses the “MyDevice” system object.

 package com.aqua.tascourse;
 import junit.framework.SystemTestCase;  
 public class ExampleTest extends SystemTestCase {        
     private MyDevice myDevice;    
 
     public void setUp() throws Exception {
         myDevice = (MyDevice)system.getSystemObject("helloWorld");
     }    
         
     /**
     */
     public void testHelloWorld() throws Exception{
         myDevice.getHelloMessage();
     }
     
     /**
     */
     public void testPing() throws Exception {
         myDevice.ping();
         // ...
         // ...
      }
  }

SUT File Example

The following code example illustrates a simple SUT file.

<sut>
    <helloWorld>
        <class>com.aqua.tascourse.MyDevice</class>
        <message>Hello TAS Course</message>       
        <fileName>C:/TAS/workspace/java/examples/capture.txt</fileName>
     </helloWorld>
</sut>

Behind the Scenes of the SUT Service

The following steps detail the flow of the SUT independent service operations.

  1. The test author uses the “getSystemObject” method of the system service.

  2. The system service refers to the properties file called: “system.properties” and searches for the name of the current SUT file.

  3. JSystem then loads the SUT file and searches for the entity called “helloWorld”.

  4. Once the file is found the class entity is found and then the java reflection is applied in order to create a new instance of the system object class.

  5. The next step in the instancing process of the system object is that the framework revises the entries under the system object entry.

  6. Each entry prepends the word “set” to the name of the entry and converts the first letter of the entry to a capital letter; this creates a method name the system now searches for this setter method using java introspection, if the method is found it is activated.

  7. Once the System Object is initiated and before it is returned from the SUT service, the system object is then entered into an internal map.

In Our Example

  1. The SystemObject class of the helloWorld example is com.aqua.tascourse.MyDevice after instancing the class, it looks for additional entries.

  2. In the “helloWorld” system object entry there are two additional entries to the class entry, the message entry and the filename entry.

  • The SUT independent service now searches for the “setMessage” setter and setFileName setter.
  • If the “setMessage” and “setFileName” setters are found they are activated with the vales found in the SUT file “Hello TAS Course” and “C:/TAS/Workspace/java/examples/captures.txt”

Nested System Object Support

The system object has the ability to contain within itself nested system objects; this enables the system object with the ability to load the configuration of the nested system object from the SUT file.

Nested System Object Code Example

The following example of code illustrates the MyDevice system object with a CLI connection member being added to it. The CLI connection is a system object is being used in this example it demonstrate how to initiate a nested system object.

package com.aqua.services.systemobject;
import jsystem.framework.system.SystemObjectImpl;
import com.aqua.sysobj.conn.CliCommand;
import com.aqua.sysobj.conn.CliConnection;
public class MyDeviceWithNestedSO extends SystemObjectImpl {

    private String message;

    public CliConnection connection;
    public void init() throws Exception {
        super.init();
    }
   
    public void close(){
        super.close();
    }
   
    public void getHelloMessage() throws Exception {
        report.report("Hello Message",getMessage(),true);
     }
   
    public void dir() throws Exception {
        CliCommand command = new CliCommand("dir");
        connection.handleCliCommand("Dir command",command);
        setTestAgainsObject(command.getResult());
    }
   
    public String getMessage() {
        return message;
    }
    
    public void setMessage(String message) {
        this.message = message;
    }
 }
~~~~

 
### SUT File Example

The example shows the SUT file of theMyDeviceWithNestedSOsystem object. Pay attention to theconnectionentity which initiates the nested CLI system object.

**Note:** The name of the class member must be identical to the name of the entry in the SUT file. (As appears in the example, “connection”)

~~~~ XML
<sut>
<helloWorld>
    <class>com.aqua.services.systemobject.MyDeviceWithNestedSO</class>
        <connection>
            <class>com.aqua.sysobj.conn.WindowsDefaultCliConnection</class> 
            <user>simpleuser</user>
            <password>simpleuser</password>
            <host>127.0.0.1</host>
        </connection>      
        <message>Hello TAS Course</message>    
</helloWorld>
</sut>
~~~~


## Array Support

The system object has the ability to contain within itself a nested array of system objects, this enables the system object with the ability to load the configuration of the nested array of system object from the SUT file. 

### Nested Array of System Object Code Example

The following example shows aMyDeviceWithNestedSOArraysystem object with an array of CLI connections.
 
~~~~ Java
package com.aqua.services.systemobject;
import jsystem.framework.system.SystemObjectImpl;
import com.aqua.sysobj.conn.CliCommand;
import com.aqua.sysobj.conn.CliConnection;

public class MyDeviceWithNestedSOArray extends SystemObjectImpl{
    private String message;
    public CliConnection[] connections;
    
    public void init() throws Exception {
        super.init();
    }
   
    public void close(){
        super.close();
    }
   
    public void getHelloMessage() throws Exception {
        report.report("Hello Message",getMessage(),true);
    }
   
    public void dir() throws Exception {
        CliCommand command = new CliCommand("dir");
        connections[0].handleCliCommand("dir",command);
    }
   
    public String getMessage() {
        return message;
    }
   
    public void setMessage(String message) {
        this.message = message;
    }
 }

~~~~
 
### SUT File Example
In the example, the SUT file of theMyDeviceWithNestedSOArraysystem object that holds an array of connections.

~~~~ xml
<sut>
    <helloWorld>
        <class>com.aqua.services.systemobject.MyDeviceWithNestedSOArray</class>
        <connections index="0">
            <class>com.aqua.sysobj.conn.WindowsDefaultCliConnection</class> 
            <user>simpleuser</user>
            <password>simpleuser</password>
            <host>127.0.0.1</host>
        </connections>      
        <connections index="1">
           <class>com.aqua.sysobj.conn.WindowsDefaultCliConnection</class> 
           <user>simpleuser</user>
           <password>simpleuser</password>
           <host>127.0.0.1</host>
        </connections>      
        <message>Hello JSystem Course</message>    
     </helloWorld>

Reference Support

This function enables the user to refer from one element in the SUT file to another element in the SUT file; as a result it avoids unnecessary duplication in the SUT file.

Note: This function enables the test author to write less without losing functionality.

Reference Support SUT Code Example

The system object is the “MyDeviceWithNestedSO”. In order to work with a reference in the SUT file there is no need to make changes to the code. The only changes required are made in the SUT file.

<helloWorld>
     <class>com.aqua.services.systemobject.MyDeviceWithNestedSO</class>
     <message>Hello TAS Course</message>    
     <fileName>C:/TAS/workspace/java/examples/capture.txt</fileName>
     <connection ref="connections/connection[@index='0']">
       <host edit="enable">10.0.0.93</host>
     </connection>
   </helloWorld>
   <helloWorld2>
     <class>com.aqua.services.systemobject.MyDeviceWithNestedSO</class>
     <connection ref="connections/connection[@index='0']"/>
   </helloWorld2>
   <connections>
     <connection index="0">
       <class>com.aqua.sysobj.conn.WindowsDefaultCliConnection</class> 
       <user>simpleuser</user>
       <password>simpleuser</password>
       <host>127.0.0.1</host>
     </connection>      
     <connection index="1">
       <class>com.aqua.sysobj.conn.WindowsDefaultCliConnection</class> 
       <user>simpleuser</user>
       <password>simpleuser</password>
       <host>10.0.0.12</host>
     </connection>      
   </connections></sut>

The SUT file defines two system objects “hellowWorld” and “helloWorld2”, the definition of the connection entity of the system objects is taken from another section in the SUT file, the “connections” section. As can be seen, the connection does not have to be defined twice; it requires to be defined once in the connections section.

Clone this wiki locally