Training Basics: Difference between revisions

From STRIDE Wiki
Jump to navigation Jump to search
No edit summary
Line 42: Line 42:
* [[Runtime_Test_Services#srTestGetParam | Reading INI-formatted input]] from a Test Suite
* [[Runtime_Test_Services#srTestGetParam | Reading INI-formatted input]] from a Test Suite


The Test Suite is called '''TestParameters''' and is implemented in two source files: '''testparameters.cpp''' and '''testparameters.h'''. The comments and descriptions are contained in the header file. Two test cases are already implemented with one test method that can be used to make changes to called '''TryStuff'''. Currently this method is set to ''not in use''.  
The Test Suite is called '''TestParameters''' and is implemented in two source files: '''testparameters.cpp''' and '''testparameters.h'''. The comments and descriptions are contained in the header file. Two test cases are already implemented and one test method that can be used to make changes to is called '''TryStuff'''. Currently the ''TryStuff'' test method is set to ''not in use''.  


First thing to do is run the ''TestParameters'' Suite. Start the '''TestApp.exe''' and use the following command:
First thing to do is run the ''TestParameters'' Suite. Start the '''TestApp.exe''' and use the following command:
Line 60: Line 60:


== File IO ==
== File IO ==
This test suite focuses on reading content from a host file in the context of an executing test logic. Note that this sample uses the [[Runtime_Test_Services#C.2B.2B_Test_Classes | srTest]] base class.
This test suite focuses on reading content from a host file to be used by the executing test logic. Note that this sample uses the [[Runtime_Test_Services#C.2B.2B_Test_Classes | srTest]] base class.


The following articles are related to this example:  
The following articles are related to this example:  
Line 68: Line 68:
* [[Runtime_Test_Services#srTestGetParam | Reading INI-formatted input]] from a Test Suite
* [[Runtime_Test_Services#srTestGetParam | Reading INI-formatted input]] from a Test Suite


The Test Suite is called '''TestFileIO''' and is implemented in two source files: '''testfileio.cpp''' and '''testfileio.h'''. The comments and descriptions are contained in the header file. One test case (method) is already implemented with one test method that can be used to make changes to called '''TryStuff'''. Currently this method is set to ''not in use''.   
The Test Suite is called '''TestFileIO''' and is implemented in two source files: '''testfileio.cpp''' and '''testfileio.h'''. The comments and descriptions are contained in the header file. One test case (method) is already implemented and one test method that can be used to make changes to is called '''TryStuff'''. Currently the ''TryStuff'' test method is set to ''not in use''.   


The Test Suite is using an INI file (''stride/samples/testfileio.ini'') to indicate what input file content to use:
The Test Suite is using an INI file (''stride/samples/testfileio.ini'') to indicate what input file content to use:
Line 77: Line 77:
   [add]
   [add]
   File          = %STRIDE_DIR%/samples/testfileio.input.add
   File          = %STRIDE_DIR%/samples/testfileio.input.add
  file_max_size = 255
 
   [mult]
   [mult]
   
   
The corresponding ''add'' input file contains the following:
The corresponding ''add'' input file contains the following (note that the ''third column'' equals the sum):


   1,2,3
   1,2,3

Revision as of 16:03, 24 November 2014

The Basics training focuses on using Test Macros, Parameters, and File IO. All testing is focused on verifying two simple routines:

 int sut_add(int x, int y);
 int sut_mult(int x, int y);

The routines are contained in software_under_test.c | h. The suggested things to Try will be focused on applying testing techniques on sut_mult().

Test Macros

This test suite focuses on leveraging assertion macros when writing test cases. Note that it is not required to use test macros. A test case (method) can simply return zero for a pass, everything is considered a fail. Refer to this article for all of the details.

The following articles are related to this example:

The Test Suite is called TestMacros and is implemented in two source files: testmacros.cpp and testmacros.h. The comments and descriptions are contained in the header file. One test case (method) is already implemented and one test method that can be used to make changes to is called TryStuff. Currently the TryStuff test method is set to not in use.

First thing to do is run the TestMacros Suite. Start the TestApp.exe and use the following command:

 stride --options_file my.opt --run "TestMacros"

You can take a look at the results in TestApp.xml.

Consider the following for TryStuff:

  • Add a test for the sut_mult() routine (remember to remove the set status routine)
  • Add an Assert macro (verses an Expect). Do you understand the difference?
  • Throw in a Note macro .. provides more viability to the test logic
  • Change the TryStuff method declaration comment (testmacros.h) and see how it shows up automatically in the test report
  • Change the TryStuff method name

Parameters

This test suite focuses on using parameters when writing test cases. Note that this sample has been implemented to (i) ensure parameters have been passed and (ii) support two different techniques for passing in parameters.

The following article are related to this example:

The Test Suite is called TestParameters and is implemented in two source files: testparameters.cpp and testparameters.h. The comments and descriptions are contained in the header file. Two test cases are already implemented and one test method that can be used to make changes to is called TryStuff. Currently the TryStuff test method is set to not in use.

First thing to do is run the TestParameters Suite. Start the TestApp.exe and use the following command:

 stride --options_file my.opt --run "TestParameters(10,10)"

You can take a look at the results in TestApp.xml.

Now run a second time and use a file with INI-formatted input:

 stride --options_file my.opt --run "TestParameters(%STRIDE_DIR%/samples/testparameters.ini)"

Consider the following for TryStuff:

  • Add a test for sut_mult() using arguments from the command line
  • Add a test for sut_mult() using your own created ini file
  • Change the content of ini file .. re-run tests

File IO

This test suite focuses on reading content from a host file to be used by the executing test logic. Note that this sample uses the srTest base class.

The following articles are related to this example:

The Test Suite is called TestFileIO and is implemented in two source files: testfileio.cpp and testfileio.h. The comments and descriptions are contained in the header file. One test case (method) is already implemented and one test method that can be used to make changes to is called TryStuff. Currently the TryStuff test method is set to not in use.

The Test Suite is using an INI file (stride/samples/testfileio.ini) to indicate what input file content to use:

 ## Required parameters used for testing file IO
 ## Using groups

 [add]
 File          = %STRIDE_DIR%/samples/testfileio.input.add
  
 [mult]

The corresponding add input file contains the following (note that the third column equals the sum):

 1,2,3
 5,6,11
 53,27,80

First thing to do is run the TestFileIO Suite. Start the TestApp.exe and use the following command:

 stride --options_file my.opt --run "TestFileIO(%STRIDE_DIR%/samples/testfileio.ini)"

You can take a look at the results in TestApp.xml.

Consider the following for TryStuff:

  • Add a test for 'sut_mult() using a different input file
    • update the testfileio.ini file to include a second file for input