Training Basics: Difference between revisions
No edit summary |
No edit summary |
||
(11 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
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()''. | 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()''. | ||
Example option file ''my.opt'' used below for running | |||
--database "%STRIDE_DIR%\SDK\Windows\out\TestApp.sidb" | |||
--device TCP:localhost:8000 | |||
== Test Macros == | == Test Macros == | ||
This | This Test Unit sample focuses on leveraging test macros when writing test cases. Note that it is '''not''' required to use test macros. A test case (method) can simply return a value to indicate ''pass'' or ''fail''. | ||
The following articles are related to this example: | The following articles are related to this example: | ||
* [[ | * [[Test Unit]] packaging options | ||
* Available [[ | * Available [[Test Macros]] | ||
* [[ | * Adding [[Notes]] to the test logic | ||
* Creating [[Test_Documentation_in_C/C%2B%2B | Doxygen style]] descriptions within header files | * Creating [[Test_Documentation_in_C/C%2B%2B | Doxygen style]] descriptions within test header files | ||
* | * How [[Running Tests]] works | ||
The Test | The Test Unit 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'' | First thing to do is run the ''TestMacros'' Test Unit. Start the '''TestApp.exe''' and use the following command: | ||
stride --options_file my.opt --run "TestMacros" | stride --options_file my.opt --run "TestMacros" | ||
You can take a look at the results | You can take a look at the results by opening the generated '''stride.html''' in your browser. | ||
Consider the following for '''TryStuff''': | Consider the following for '''TryStuff''': | ||
* Add | * Add test code for the ''sut_mult()'' routine (remember to remove the ''set status'' call) | ||
* Add an ''Assert'' macro (verses an ''Expect''). Do you understand the difference? | * Add an ''Assert'' macro (verses an ''Expect''). Do you understand the difference? | ||
* Throw in a ''Note'' macro .. provides more viability to the test logic | * Throw in a ''Note'' macro .. provides more viability to the test logic | ||
* Change the '' | * Change the test method documentation (in ''testmacros.h'') and see how it shows up automatically in the test report | ||
* Change the | * Change the test method name | ||
== Parameters == | == Parameters == | ||
This | This Test Unit sample 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 articles are related to this example: | The following articles are related to this example: | ||
* [[Parameterized Test Units | Passing | * [[Parameterized Test Units | Passing parameter input]] to a Test Unit | ||
* [[Runtime_Test_Services#srTestGetParam | Reading parameters]] from a Test Unit | |||
* [[Runtime_Test_Services#srTestGetParam | Reading | |||
The Test | The Test Unit 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'' | First thing to do is run the ''TestParameters'' Test Unit. Start the '''TestApp.exe''' and use the following command: | ||
stride --options_file my.opt --run "TestParameters(10,10)" | stride --options_file my.opt --run "TestParameters(10,10)" | ||
You can take a look at the results | You can take a look at the results by opening the generated '''stride.html''' in your browser. | ||
Now run a second time and use a file with INI-formatted input: | Now run a second time and use a file with INI-formatted input: | ||
Line 55: | Line 59: | ||
Consider the following for '''TryStuff:''' | Consider the following for '''TryStuff:''' | ||
* Add | * Add test code for ''sut_mult()'' using arguments from the command line | ||
* Add | * Add test code for ''sut_mult()'' using your own created ini file | ||
* Change the content of ini file .. re-run the | * Change the content of the ini file .. re-run the Test Unit | ||
== File IO == | == File IO == | ||
This | This Test Unit sample 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: | ||
* [[File_Transfer_Services | File IO Services]] | * [[File_Transfer_Services | File IO Services]] | ||
* [[Passing | * [[Parameterized Test Units | Passing parameter input]] to a Test Unit | ||
The Test | The Test Unit 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 | The Test Unit is using an INI file (''stride/samples/testfileio.ini'') to indicate what input file content to use: | ||
## Required parameters used for testing file IO | ## Required parameters used for testing file IO | ||
Line 76: | Line 79: | ||
[add] | [add] | ||
File | File = %STRIDE_DIR%/samples/testfileio.input.add | ||
[mult] | [mult] | ||
Line 86: | Line 89: | ||
53,27,80 | 53,27,80 | ||
First thing to do is run the ''TestFileIO'' | First thing to do is run the ''TestFileIO'' Test Unit. Start the '''TestApp.exe''' and use the following command: | ||
stride --options_file my.opt --run "TestFileIO(%STRIDE_DIR%/samples/testfileio.ini)" | stride --options_file my.opt --run "TestFileIO(%STRIDE_DIR%/samples/testfileio.ini)" | ||
You can take a look at the results | You can take a look at the results by opening the generated '''stride.html''' in your browser. | ||
Consider the following for '''TryStuff:''' | Consider the following for '''TryStuff:''' | ||
* Add | * Add test code for ''sut_mult()'' using a different input file | ||
* Update the ''testfileio.ini'' file to include a second file for input | * Update the ''testfileio.ini'' file to include a second file for input |
Latest revision as of 21:37, 6 July 2015
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().
Example option file my.opt used below for running
--database "%STRIDE_DIR%\SDK\Windows\out\TestApp.sidb" --device TCP:localhost:8000
Test Macros
This Test Unit sample focuses on leveraging test macros when writing test cases. Note that it is not required to use test macros. A test case (method) can simply return a value to indicate pass or fail.
The following articles are related to this example:
- Test Unit packaging options
- Available Test Macros
- Adding Notes to the test logic
- Creating Doxygen style descriptions within test header files
- How Running Tests works
The Test Unit 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 Test Unit. Start the TestApp.exe and use the following command:
stride --options_file my.opt --run "TestMacros"
You can take a look at the results by opening the generated stride.html in your browser.
Consider the following for TryStuff:
- Add test code for the sut_mult() routine (remember to remove the set status call)
- 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 test method documentation (in testmacros.h) and see how it shows up automatically in the test report
- Change the test method name
Parameters
This Test Unit sample 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 articles are related to this example:
- Passing parameter input to a Test Unit
- Reading parameters from a Test Unit
The Test Unit 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 Test Unit. 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 by opening the generated stride.html in your browser.
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 test code for sut_mult() using arguments from the command line
- Add test code for sut_mult() using your own created ini file
- Change the content of the ini file .. re-run the Test Unit
File IO
This Test Unit sample 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:
- File IO Services
- Passing parameter input to a Test Unit
The Test Unit 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 Unit 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 Test Unit. 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 by opening the generated stride.html in your browser.
Consider the following for TryStuff:
- Add test code for sut_mult() using a different input file
- Update the testfileio.ini file to include a second file for input