Test Class Sample

From STRIDE Wiki
Revision as of 14:47, 3 June 2009 by Mikee (talk | contribs)
Jump to: navigation, search

Tests Description

NOTE: each of the example test classes is grouped in namespace corresponding to its category (e.g. Basic or Runtime Services). This is something shown for organizational purposes only -- it is not a general requirement that test classes be placed into namespaces.

Basic

These examples cover the simplest, easiest way to code a STRIDE test class. These examples use simple POD return types to indicate status.

Simple

This example demonstrates passing and failing tests using the four primary POD types that infer status from (int, bool, short, and char).

Fixtures

This example demonstrates how to use setup and teardown fixtures. The setup and teardown methods are called immediately before and after the execution of each test method, respectively.

Exceptions

This example demonstrates how exceptions thrown from a test method are caught by the intercept module and noted in the results. Any exception that is caught by the harness is assumed to indicate failure. If you want to write tests for expected exceptions, consider using our Pass/Fail_Macros#Exception_Macros exception macros

Runtime Services

These examples cover basic usage of the Runtime Test Services API (as declared in srtest.h).

Simple

This example demonstrates how to use srTestCaseSetStatus to set status, srTestCaseAddComment to add a comment, and srTEST_ADD_COMMENT_WITH_LOCATION to add a comment that automatically includes line and file information.

Dynamic

This example demonstrates how to use srTestSuiteAddSuite, srTestSuiteAddCase, srTestSuiteAddAnnotation, and srTestAnnotationAddComment for dynamic suite, test, and annotation creation in the context of a single test method.

Override

This example demonstrates how to use srTestCaseSetStatus to override the status that would otherwise be inferred from the return value.

VarComment

This example demonstrates the use of printf style format strings with srTestCaseAddComment.

srTest

These examples show to how to use the stride::srTest base class for your test classes. When you publicly inherit from srTest, you get access to default testCase and testSuite members and their associated methods.

Simple

This example demonstrates the use of testCase.setStatus to set the status for test cases.

Dynamic

This example demonstrates how to use testSuite.AddSuite, testSuite.AddTest, testSuite.AddAnnotation, and testSuite.AddAnnotation.AddComment for dynamic suite, test case, and annotation creation within the context of one test method.