Scl test teardown: Difference between revisions

From STRIDE Wiki
Jump to navigation Jump to search
No edit summary
Line 29: Line 29:


== 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
    srTestCaseAddComment(srTEST_CASE_DEFAULT, "setup called");
    * and add comments.
  }
    *
  void teardown (void)  
    */
  {
    #include <srtest.h>
    srTestCaseAddComment(srTEST_CASE_DEFAULT, "teardown called");
  }
    class RuntimeServices_fixtures {
  void tc_ExpectPass(void)  
    public:
  {
        void setup (void)  
    srTestCaseAddComment(srTEST_CASE_DEFAULT, "this test should pass");
        {
    srTestCaseSetStatus(srTEST_CASE_DEFAULT, srTEST_PASS, 0);  
            srTestCaseAddComment(srTEST_CASE_DEFAULT, "setup called");
  }
        }
  void tc_ExpectFail(void)  
        void teardown (void)  
  {
        {
    srTestCaseAddComment(srTEST_CASE_DEFAULT, "this test should fail");
            srTestCaseAddComment(srTEST_CASE_DEFAULT, "teardown called");
    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 ==
== See Also ==

Revision as of 00:33, 2 October 2008

The scl_test_teardown pragma

The scl_test_teardown pragma declares a member method to be a teardown fixture for an existing test unit. The teardown method will be called after the execution of each test method.

Syntax

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

Notes

  • This pragma identifies the teardown fixture of an existing test unit, i.e. either a class with scl_test_class applied to it, or a function name with scl_test_flist applied to it.
  • There may be only one teardown fixture per test unit.
  • The test unit name must match the class-name parameter of an scl_test_class pragma, or the test-unit-name parameter of an scl_test_flist pragma that has already been declared.
  • This pragma can only work in STRIDE version 2.1 or later.
  • The host PC must also have a recent distribution of ActiveState Perl installed.

Example

#include <srtest.h>

class RuntimeServices_fixtures {
public:
  void setup (void) 
  {
    srTestCaseAddComment(srTEST_CASE_DEFAULT, "setup called");
  }
  void teardown (void) 
  {
    srTestCaseAddComment(srTEST_CASE_DEFAULT, "teardown called");
  }
  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
#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 classes.