Scl test setup: Difference between revisions

From STRIDE Wiki
Jump to navigation Jump to search
(New page: = The scl_test_setup pragma = The scl_test_setup pragma declares a member method to be a setup fixture for the class. If specified, the setup method will be called before to the execution...)
 
 
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
= The scl_test_setup pragma =
= The scl_test_setup pragma =


The scl_test_setup pragma declares a member method to be a setup fixture for the class. If specified, the setup method will be called before to the execution of each test method.
The ''scl_test_setup'' pragma declares a member method to be a setup fixture for an existing test unit. The setup method will be called before the execution of each test method.


== Syntax ==
== Syntax ==
Line 13: Line 13:
|-
|-
| ''test-unit-name''
| ''test-unit-name''
| String
| Identifier
| Name of a captured test unit.
| Name of a captured test unit.
|-  
|-  
| ''function-name''
| ''function-name''
| String
| Identifier
| Name of a member function of the test unit to be used as a setup fixture. If specified, the setup method will be called before the execution of each test method.
| Name of a member function of the test unit to be used as a setup fixture.  
|}
|}


== Notes ==
== Notes ==
* This pragma can only work in STRIDE version 2.1 or later.
* This pragma identifies the setup fixture of an existing test unit, i.e. either a class with [[scl_test_class]] applied to it, a set of functions with [[scl_test_flist]] applied to it, or a C struct with [[scl_test_cclass]] applied to it.
* The host PC must also have a recent distribution of ActiveState Perl installed.
* There may be only one setup fixture per test unit.
* Refer to the [[Test_Units]] page for more information on capturing and qualifying test classes.


== Example ==
== Example ==
<source lang=cpp>
#include <srtest.h>


    /*
class RuntimeServices_fixtures {
    * Example test class using Runtime test services
public:
    *
  void setup (void)  
    * @description
  {
    * this is a basic test class that uses the C runtime API to set status
    srTestCaseAddAnnotation(srTEST_CASE_DEFAULT, srTEST_ANNOTATION_LEVEL_INFO, srNULL, "setup called");
    * and add comments.
  }
    *
  void teardown (void)  
    */
  {
    #include <srtest.h>
    srTestCaseAddAnnotation(srTEST_CASE_DEFAULT, srTEST_ANNOTATION_LEVEL_INFO, srNULL, "teardown called");
    class RuntimeServices_fixtures {
  }
    public:
  void tc_ExpectPass(void)  
        void setup (void)  
  {
        {
    srTestCaseAddAnnotation(srTEST_CASE_DEFAULT, srTEST_ANNOTATION_LEVEL_INFO, srNULL, "this test should pass");
            srTestCaseAddComment(srTEST_CASE_DEFAULT, "setup called");
    srTestCaseSetStatus(srTEST_CASE_DEFAULT, srTEST_PASS, 0);  
        }
  }
        void teardown (void)  
  void tc_ExpectFail(void)  
        {
  {
            srTestCaseAddComment(srTEST_CASE_DEFAULT, "teardown called");
    srTestCaseAddAnnotation(srTEST_CASE_DEFAULT, srTEST_ANNOTATION_LEVEL_ERROR, srNULL, "this test should fail");
        }
    srTestCaseSetStatus(srTEST_CASE_DEFAULT, srTEST_FAIL, 0);  
        void tc_ExpectPass(void)  
  }
        {
};
            srTestCaseAddComment(srTEST_CASE_DEFAULT, "this test should pass");
            srTestCaseSetStatus(srTEST_CASE_DEFAULT, srTEST_PASS, 0);  
        }
        void tc_ExpectFail(void)  
        {
            srTestCaseAddComment(srTEST_CASE_DEFAULT, "this test should fail");
            srTestCaseSetStatus(srTEST_CASE_DEFAULT, srTEST_FAIL, 0);  
        }
    };
      
      
    #ifdef _SCL
#ifdef _SCL
    #pragma scl_test_class(RuntimeServices_fixtures)
#pragma scl_test_class(RuntimeServices_fixtures)
    #pragma scl_test_setup(RuntimeServices_fixtures, setup)
#pragma scl_test_setup(RuntimeServices_fixtures, setup)
    #pragma scl_test_teardown(RuntimeServices_fixtures, teardown)
#pragma scl_test_teardown(RuntimeServices_fixtures, teardown)
    #endif
#endif
</source>
 
== See Also ==
* Refer to the [[Test Units]] page for more information on capturing and qualifying test units.
 
[[Category: Test Units]]
[[Category: SCL]]

Latest revision as of 19:24, 5 August 2014

The scl_test_setup pragma

The scl_test_setup pragma declares a member method to be a setup fixture for an existing test unit. The setup method will be called before the execution of each test method.

Syntax

#pragma scl_test_setup(test-unit-name, function-name)
Parameters Type Description
test-unit-name Identifier Name of a captured test unit.
function-name Identifier Name of a member function of the test unit to be used as a setup fixture.

Notes

  • This pragma identifies the setup fixture of an existing test unit, i.e. either a class with scl_test_class applied to it, a set of functions with scl_test_flist applied to it, or a C struct with scl_test_cclass applied to it.
  • There may be only one setup fixture per test unit.

Example

#include <srtest.h>

class RuntimeServices_fixtures {
public:
  void setup (void) 
  {
    srTestCaseAddAnnotation(srTEST_CASE_DEFAULT, srTEST_ANNOTATION_LEVEL_INFO, srNULL, "setup called");
  }
  void teardown (void) 
  {
    srTestCaseAddAnnotation(srTEST_CASE_DEFAULT, srTEST_ANNOTATION_LEVEL_INFO, srNULL, "teardown called");
  }
  void tc_ExpectPass(void) 
  {
    srTestCaseAddAnnotation(srTEST_CASE_DEFAULT, srTEST_ANNOTATION_LEVEL_INFO, srNULL, "this test should pass");
    srTestCaseSetStatus(srTEST_CASE_DEFAULT, srTEST_PASS, 0); 
  }
  void tc_ExpectFail(void) 
  {
    srTestCaseAddAnnotation(srTEST_CASE_DEFAULT, srTEST_ANNOTATION_LEVEL_ERROR, srNULL, "this test should fail");
    srTestCaseSetStatus(srTEST_CASE_DEFAULT, srTEST_FAIL, 0); 
  }
};
    
#ifdef _SCL
#pragma scl_test_class(RuntimeServices_fixtures)
#pragma scl_test_setup(RuntimeServices_fixtures, setup)
#pragma scl_test_teardown(RuntimeServices_fixtures, teardown)
#endif

See Also

  • Refer to the Test Units page for more information on capturing and qualifying test units.