Difference between revisions of "TestUnit Integration"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with 'This document assumes that you have already read this page: http://wiki.secondlife.com/wiki/LSL_Test_Harness, with special attention to the section called, "The Test Unit(s)". ...')
 
m (<nowiki><lsl></nowiki> tag conversion)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
This document assumes that you have already read this page: http://wiki.secondlife.com/wiki/LSL_Test_Harness, with special attention to the  
====This document assumes that you have already read this page: http://wiki.secondlife.com/wiki/LSL_Test_Harness, with special attention to the section called, "The Test Unit(s)".====
 


section called, "The Test Unit(s)".


First, open the Test Unit template page here: http://wiki.secondlife.com/wiki/TestUnit_TestScript.lsl
First, open the Test Unit template page here: http://wiki.secondlife.com/wiki/TestUnit_TestScript.lsl
Line 8: Line 8:
https://wiki.secondlife.com/wiki/TestUnit_MATH_Binary_Operators.lsl
https://wiki.secondlife.com/wiki/TestUnit_MATH_Binary_Operators.lsl


The Test Units run tests that you create yourself, and insert into the Test Unit Template. They have 4 parts that require attention, Global Varibles,  
The Test Units run tests that you create yourself, and insert into the Test Unit Template. They have 4 parts that require attention, Global Variables,  


Runtest, Report and Initialize. Before you sit down and start adding anything to a Test Unit, you need to define what you want to accomplish.  
Runtest, Report and Initialize. Before you sit down and start adding anything to a Test Unit, you need to define what you want to accomplish.  
Line 16: Line 16:
I will break them down the 4 major sections where you, the author, will be adding data, below:
I will break them down the 4 major sections where you, the author, will be adding data, below:


* Global variable declaration
= Global variable declaration =
This is where you place all of the variable declarations for the variables that you will use in your Test Unit script. This includes the  
This is where you place all of the variable declarations for the variables that you will use in your Test Unit script. This includes the  


Line 22: Line 22:


from the Binary Operators test script:
from the Binary Operators test script:
<lsl>
<source lang="lsl2">
// Global Variables
// Global Variables
Line 50: Line 50:
integer BitwiseRightShift_PASS;
integer BitwiseRightShift_PASS;
integer BitwiseExclusiveOR_PASS;  
integer BitwiseExclusiveOR_PASS;  
</lsl>
</source>


* Runtest
= Runtest =
This section is where the tests are actually run. It is broken down into three discrete parts. In most cases, the first is a series of  
This section is where the tests are actually run. It is broken down into three discrete parts. In most cases, the first is a series of  


conditional statements against the data set that you established, where each conditional statement sets a pass bit. Here is an example, from the  
conditional statements against the data set that you established, where each conditional statement sets a pass bit. Here is an example, from the  


Binary Operators Tetst Unit:
Binary Operators Test Unit:
<lsl>
<source lang="lsl2">
RunTest()
RunTest()
{
{
Line 92: Line 92:
            ArithmeticDivision_PASS = 1;
            ArithmeticDivision_PASS = 1;
        }
        }
</lsl>         
</source>         
...and so on.
...and so on.
Line 98: Line 98:


test, a global PASS variable is set for the entire Test Unit:
test, a global PASS variable is set for the entire Test Unit:
<lsl>
<source lang="lsl2">
//check to see if any failures occured.  
//check to see if any failures occured.  
  integer pass = ArithmeticAddition_PASS &
  integer pass = ArithmeticAddition_PASS &
Line 118: Line 118:
                  BitwiseRightShift_PASS &
                  BitwiseRightShift_PASS &
                  BitwiseExclusiveOR_PASS;
                  BitwiseExclusiveOR_PASS;
</lsl>                       
</source>                       
The last part of the Runtest section of the Test Unit broadcases your gobal pass/fail result to the main harness, and looks like this:
The last part of the Runtest section of the Test Unit broadcasts your global pass/fail result to the main harness, and looks like this:
<lsl>
<source lang="lsl2">
    // if all of the individual cases pass, test passes.                                 
    // if all of the individual cases pass, test passes.                                 
    if( pass )
    if( pass )
Line 130: Line 130:
        llMessageLinked(LINK_SET, passFailChannel, "FAIL", NULL_KEY);
        llMessageLinked(LINK_SET, passFailChannel, "FAIL", NULL_KEY);
    }                               
    }                               
</lsl>
</source>
* Report
= Report =
The Report mechanism takes your pass / fail data, and maps it to results output in three ways, QUIET, NORMAL, and VERBOSE. How  
The Report mechanism takes your pass / fail data, and maps it to results output in three ways, QUIET, NORMAL, and VERBOSE. How  


Line 142: Line 142:
Here is an example of what a section of the VERBOSE report string building in the Binary Operators Test Unit:
Here is an example of what a section of the VERBOSE report string building in the Binary Operators Test Unit:


<lsl>
<source lang="lsl2">


//VERBOSE - highest level of reporting
//VERBOSE - highest level of reporting
Line 162: Line 162:
     
     
} // end verbose
} // end verbose
</lsl>
</source>


This is what the section looks like that sends the report string variable to the Coordinator:
This is what the section looks like that sends the report string variable to the Coordinator:
<lsl>
<source lang="lsl2">
//AddUnitReport()
//AddUnitReport()
//send to Coordinator on the broadcastChannel the selected report
//send to Coordinator on the broadcastChannel the selected report
//format example -> AddUnitReport::unitKey::00000-0000-0000-00000::Report::Successful Completion of Test
//format example -> AddUnitReport::unitKey::00000-0000-0000-00000::Report::Successful Completion of Test
llSay( controlChannel, "AddUnitReport::unitKey::" + (string)llGetKey() + "::Report::" + reportString);
llSay( controlChannel, "AddUnitReport::unitKey::" + (string)llGetKey() + "::Report::" + reportString);
</lsl>
</source>


* Initialize
= Initialize =
This section is used solely to place the name of your Test Unit's name in hovertext above the Test Unit in world. The following is an  
This section is used solely to place the name of your Test Unit's name in hovertext above the Test Unit in world. The following is an  


example of how that looks:
example of how that looks:
<lsl>
<source lang="lsl2">
Initialize()
Initialize()
{
{
    llSetText( "MATH_BinaryOperators", <255,255,255>, 1);
    llSetText( "MATH_BinaryOperators", <255,255,255>, 1);
}
}
</lsl>
</source>
 
 
=Reminder=
Don't forget to add the appropriate information to your TestUnit_nc (TestUnit Notecard). Here is what is contained in the notecard for this test:
            UnitName:[BinaryOperators]
            GroupName:[MATH]

Latest revision as of 13:39, 25 January 2015

This document assumes that you have already read this page: http://wiki.secondlife.com/wiki/LSL_Test_Harness, with special attention to the section called, "The Test Unit(s)".

First, open the Test Unit template page here: http://wiki.secondlife.com/wiki/TestUnit_TestScript.lsl

I will use the Binary Operators Test Unit in this exmaple: https://wiki.secondlife.com/wiki/TestUnit_MATH_Binary_Operators.lsl

The Test Units run tests that you create yourself, and insert into the Test Unit Template. They have 4 parts that require attention, Global Variables,

Runtest, Report and Initialize. Before you sit down and start adding anything to a Test Unit, you need to define what you want to accomplish.

Choose an area of functionality and extract all of the data that you need to go into, and out of the test.

I will break them down the 4 major sections where you, the author, will be adding data, below:

Global variable declaration

This is where you place all of the variable declarations for the variables that you will use in your Test Unit script. This includes the

defaults that the script uses. It is good practice to create a pass variable for each test that you put into the Test Unit. The following is an excerpt

from the Binary Operators test script:

			// Global Variables
			
			/// These variables are used in all LSL Test Unit scripts.
			integer toAllChannel = -255;           // (for all Test Units)general channel - linked message
			integer passFailChannel = -355;        // test scripts channel for cummunicating pass/fail - linked message
			integer debug = 0;                     // level of debug message
			integer debugChannel = DEBUG_CHANNEL;  // output channel for debug messages
			
			// These variables are unique to this script.
			integer ArithmeticAddition_PASS;                    
			integer ArithmeticSubtraction_PASS;                  
			integer ArithmeticMultiplication_PASS;                 
			integer ArithmeticDivision_PASS;                  
			integer ArithmeticModulo_PASS;                    
			integer ArithmeticGreaterThan_PASS;               
			integer ArithmeticLessThan_PASS;
			integer ArithmeticGreaterThanOrEqualTo_PASS; 
			integer ArithmeticLessThanOrEqualTo_PASS; 
			integer LogicalInequality_PASS; 
			integer LogicalEquality_PASS; 
			integer LogicalAND_PASS; 
			integer LogicalOR_PASS; 
			integer BitwiseAND_PASS; 
			integer BitwiseOR_PASS; 
			integer BitwiseLeftShift_PASS; 
			integer BitwiseRightShift_PASS;
			integer BitwiseExclusiveOR_PASS;

Runtest

This section is where the tests are actually run. It is broken down into three discrete parts. In most cases, the first is a series of

conditional statements against the data set that you established, where each conditional statement sets a pass bit. Here is an example, from the

Binary Operators Test Unit:

			RunTest()
			{
			        // initialize PASS variable        
			        ArithmeticAddition_PASS = 0;
			        // Compare data against criteria in GetType function, which returns an integer corresponding to the type.        
			        if (1 + 1 == 2)
			        {
			            ArithmeticAddition_PASS = 1;
			        }
        			
			        // initialize PASS variable        
			        ArithmeticSubtraction_PASS = 0;
			        // Compare data against criteria in GetType function, which returns an integer corresponding to the type.        
			        if (1 - 1 == 0)
			        {
			            ArithmeticSubtraction_PASS = 1;
			        }
			        
			        // initialize PASS variable        
			        ArithmeticMultiplication_PASS = 0;
			        // Compare data against criteria in GetType function, which returns an integer corresponding to the type.        
			        if (2 * 2 == 4)
			        {
			            ArithmeticMultiplication_PASS = 1;
			        }
			        
			        // initialize PASS variable        
			        ArithmeticDivision_PASS = 0;
			        // Compare data against criteria in GetType function, which returns an integer corresponding to the type.
			        if (4 / 2 == 2)
			        {
			            ArithmeticDivision_PASS = 1;
			        }

...and so on.

The second part in the Runtest section is where you look at your PASS variables to check for any failures. If there are no failures in the

test, a global PASS variable is set for the entire Test Unit:

			//check to see if any failures occured. 
			   integer pass = ArithmeticAddition_PASS &
			                  ArithmeticSubtraction_PASS &
			                  ArithmeticMultiplication_PASS &
			                  ArithmeticModulo_PASS &
			                  ArithmeticDivision_PASS &
			                  ArithmeticGreaterThan_PASS &
			                  ArithmeticLessThan_PASS &
			                  ArithmeticGreaterThanOrEqualTo_PASS &
			                  ArithmeticLessThanOrEqualTo_PASS &
			                  LogicalInequality_PASS &
			                  LogicalEquality_PASS &
			                  LogicalAND_PASS &
			                  LogicalOR_PASS &
			                  BitwiseAND_PASS &
			                  BitwiseOR_PASS &
			                  BitwiseLeftShift_PASS &                       
			                  BitwiseRightShift_PASS &
			                  BitwiseExclusiveOR_PASS;

The last part of the Runtest section of the Test Unit broadcasts your global pass/fail result to the main harness, and looks like this:

			     // if all of the individual cases pass, test passes.                                
			     if( pass )
			     {
			       llMessageLinked(LINK_SET, passFailChannel, "PASS", NULL_KEY);
			     }
			     else
			     {
			         llMessageLinked(LINK_SET, passFailChannel, "FAIL", NULL_KEY);
			     }

Report

The Report mechanism takes your pass / fail data, and maps it to results output in three ways, QUIET, NORMAL, and VERBOSE. How

you set up your reporting mechanisms is up to you, but all three should be available to the Test Harness for reporting, as the Harness Coordinator

has these options built in, in the controller. For each report type, construct report strings based on what ever level you want to provide for the

data that you tested in your Test Unit. It is up to you how you will package your report data, to be sent back to the report utility in the harness.

Here is an example of what a section of the VERBOSE report string building in the Binary Operators Test Unit:

			//VERBOSE - highest level of reporting
			if( reportType == "VERBOSE" )
			{
			         reportString = "///////////////////////////////////////////////////////////////////////////////////////////" + "\n"+
			            "// Type: ArithmeticAddition" + "\n" +
			            "// Returns an integer representing the integer type constant" + "\n" +
			            "// • ArithmeticAddition = 1" + "\n" +
			            "///////////////////////////////////////////////////////////////////////////////////////////" + "\n" +
			            "PASS/FAIL -> " + ArithmeticAddition_PASSstring + "\n\n" +
			
			            "/////////////////////////////////////////////////////////////////////////////////" + "\n" +
			            "// Type: BitwiseExclusiveOR" + "\n" +
			            "// Returns an integer representing the invalid data type constant" + "\n" +
			            "// • BitwiseExclusiveOR = 0" + "\n" +
			            "/////////////////////////////////////////////////////////////////////////////////" + "\n" +
			            "PASS/FAIL -> " + BitwiseExclusiveOR_PASSstring + "\n\n";                 
			    
			} // end verbose

This is what the section looks like that sends the report string variable to the Coordinator:

			//AddUnitReport()
			//send to Coordinator on the broadcastChannel the selected report
			//format example -> AddUnitReport::unitKey::00000-0000-0000-00000::Report::Successful Completion of Test
			llSay( controlChannel, "AddUnitReport::unitKey::" + (string)llGetKey() + "::Report::" + reportString);

Initialize

This section is used solely to place the name of your Test Unit's name in hovertext above the Test Unit in world. The following is an

example of how that looks:

			Initialize()
			{
			    llSetText( "MATH_BinaryOperators", <255,255,255>, 1);
			}


Reminder

Don't forget to add the appropriate information to your TestUnit_nc (TestUnit Notecard). Here is what is contained in the notecard for this test:

            UnitName:[BinaryOperators]
            GroupName:[MATH]