Training Test Macros: Difference between revisions
m (Marku moved page Training Basics to Training Test Macros) |
|||
(19 intermediate revisions by 4 users not shown) | |||
Line 2: | Line 2: | ||
This Training Module focuses on the basics of writing and executing tests. It covers the following topics: | This Training Module focuses on the basics of writing and executing tests. It covers the following topics: | ||
* The | * The C++ class [[Test_Units | Test Unit packaging]] option | ||
* How to leverage [[Test_Macros | Test Macros]] | * How to leverage [[Test_Macros | Test Macros]] | ||
* Using [[Test_Macros#Notes | Notes]] and [[Test_Log | Test Logs]], what is the difference? | * Using [[Test_Macros#Notes | Notes]] and [[Test_Log | Test Logs]], what is the difference? | ||
Line 9: | Line 9: | ||
The test unit is implemented in two source files: '''TestBasic.cpp''' and '''TestBasic.h'''. The comments and descriptions are contained in '''TestBasic.h'''. | |||
The Test Unit has test cases already implemented (used for reference) and has a test method that you are required to implement (called '''Exercise'''). Currently this method is empty and returns a ''NOT IN USE'' status. | |||
== Instructions == | == Instructions == | ||
Line 27: | Line 17: | ||
=== Build and Run TestApp === | === Build and Run TestApp === | ||
* Build TestApp | * [[Building_an_Off-Target_Test_App#Build_Steps | Build TestApp]] using the SDK makefile | ||
* Invoke TestApp found in the ''/out/bin'' directory | |||
* Invoke TestApp | * If you have not created an option file, please refer to [[Training_Getting_Started#Run_Training_Tests| setup]] | ||
* | |||
* Execute the ''Test Basic'' Test Units | * Execute the ''Test Basic'' Test Units | ||
> stride - | > stride --options_file myoptions.txt --run TestBasic | ||
Loading database... | Loading database... | ||
Connecting to device... | Connecting to device... | ||
Executing... | Executing... | ||
test unit " | test unit "TestBasic" | ||
> 3 passed | > 3 passed, 1 failed, 0 in progress, 1 not in use. | ||
-------------------------------------------------------------- | -------------------------------------------------------------- | ||
Summary: | Summary: 3 passed, 1 failed, 0 in progress, 1 not in use. | ||
Disconnecting from device... | Disconnecting from device... | ||
Saving result file... | Saving result file... | ||
You can also review the details of the test results using a Browser. Open [[Building_an_Off-Target_Test_App#Interpreting_Results | TestApp.xml ]] which can be found in the sample_src directory (based on the output option). By opening the xml file in a web browser the xsl is automatically applied to create html. | |||
=== Implement Exercises === | === Implement Exercises === | ||
Now edit the training source code to complete the following exercises: | Now edit the training source code to complete the following exercises: | ||
; | ;Exercise() | ||
* '''Assignment 1:''' Add an ''srNOTE'' to <tt> | * '''Assignment 1:''' Add an ''srNOTE'' to <tt>Exercise()</tt> that will add a simple message to the test report (e.g. "Exercise ...") | ||
** ''Hint:'' You will probably want to read about [[Test Macros]] | ** ''Hint:'' You will probably want to read about [[Test Macros]] | ||
** ''Hint:'' srTestCaseSetStatus(srTEST_CASE_DEFAULT, srTEST_NOTINUSE, 0) is a placeholder to be removed when you add your test code. | |||
* '''Assignment 2:''' Within <tt> | * '''Assignment 2:''' Within <tt>Exercise()</tt> validate that <tt>sut_mult(1,1)</tt> does NOT equal <tt>sut_add(1,1)</tt> | ||
** ''Hint:'' You will use a [[Test Macros | Test Macro]]. | ** ''Hint:'' You will use a [[Test Macros | Test Macro]]. | ||
=== | === Check Results === | ||
* Before you rebuild <tt>TestApp.exe</tt>, you will need to shut it down by entering 'q' in its console window or closing the window directly. | * Before you rebuild <tt>TestApp.exe</tt>, you will need to shut it down by entering 'q' in its console window or closing the window directly. | ||
Line 89: | Line 54: | ||
* After rebuilding, invoke <tt>TestApp.exe</tt> once again. | * After rebuilding, invoke <tt>TestApp.exe</tt> once again. | ||
* Execute only '' | * Execute only ''TestBasic'' using the stride runner: | ||
> stride - | > stride --options_file myoptions.txt --run TestBasic | ||
Loading database... | Loading database... | ||
Connecting to device... | Connecting to device... | ||
Executing... | Executing... | ||
test unit " | test unit "TestBasic" | ||
> 4 passed, | > 4 passed, 1 failed, 0 in progress, 0 not in use. | ||
-------------------------------------------------------------- | -------------------------------------------------------------- | ||
Summary: 4 passed, | Summary: 4 passed, 1 failed, 0 in progress, 0 not in use. | ||
Disconnecting from device... | Disconnecting from device... | ||
Line 108: | Line 73: | ||
=== Run and Publish Results === | === Run and Publish Results === | ||
When you have completed the Exercise(s) publish your results to Test Space. | When you have completed the Exercise(s) publish your results to Test Space(--space TestBasic). If you have not added test space options to your options file (<tt>myoptions.txt</tt>) please see [[Training_Getting_Started#Test_Space_Access| testspace access]]. | ||
> stride --options_file myoptions.txt --run TestBasic --space TestBasic --upload | |||
> stride - | |||
Loading database... | Loading database... | ||
Connecting to device... | Connecting to device... | ||
Executing... | Executing... | ||
test unit " | test unit "TestBasic" | ||
> 4 passed, | > 4 passed, 1 failed, 0 in progress, 0 not in use. | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
Summary: | Summary: 4 passed, 1 failed, 0 in progress, 0 not in use. | ||
Disconnecting from device... | Disconnecting from device... | ||
Saving result file... | Saving result file... | ||
Uploading to test space... | Uploading to test space... | ||
=== Validate Uploaded Results === | |||
Navigate to Test Space using your browser, then validate your results against the pre-configured baseline. For details, please see [[Training_Getting_Started#Confirming_Training_Exercise_Results | Confirming Training Exercise Results]] | |||
Note: This space has been set up with a Baseline of [[Training_Getting_Started#Test_Space_Access | ''expected test results'']] that you can use to validate your results. | Note: This space has been set up with a Baseline of [[Training_Getting_Started#Test_Space_Access | ''expected test results'']] that you can use to validate your results. | ||
Line 152: | Line 111: | ||
=== Samples === | === Samples === | ||
* [[ | * [[Test_Class_Sample|Test Class Sample]] - Specifically the [[Test_Class_Sample#Basic|Basic Simple]] Test Unit | ||
* [[Test_Macros_Sample|Test Macro Sample]] - This sample covers simple uses of each of the Test Macros. | * [[Test_Macros_Sample|Test Macro Sample]] - This sample covers simple uses of each of the Test Macros. | ||
Note - Other Test Unit Samples related to packaging that are useful are the following: | Note - Other Test Unit Samples related to packaging that are useful are the following: | ||
* [[Test_CClass_Sample|Test C Class Sample]] | * [[Test_CClass_Sample|Test C Class Sample]] | ||
* [[Test_Function_List_Sample|Test Function List Sample]] | |||
[[Category: Training]] | [[Category: Training]] |
Latest revision as of 14:50, 22 November 2014
Objectives
This Training Module focuses on the basics of writing and executing tests. It covers the following topics:
- The C++ class Test Unit packaging option
- How to leverage Test Macros
- Using Notes and Test Logs, what is the difference?
- Creating Test Documentation via the build process
- Executing Tests using the Runner
The test unit is implemented in two source files: TestBasic.cpp and TestBasic.h. The comments and descriptions are contained in TestBasic.h.
The Test Unit has test cases already implemented (used for reference) and has a test method that you are required to implement (called Exercise). Currently this method is empty and returns a NOT IN USE status.
Instructions
Build and Run TestApp
- Build TestApp using the SDK makefile
- Invoke TestApp found in the /out/bin directory
- If you have not created an option file, please refer to setup
- Execute the Test Basic Test Units
> stride --options_file myoptions.txt --run TestBasic Loading database... Connecting to device... Executing... test unit "TestBasic" > 3 passed, 1 failed, 0 in progress, 1 not in use. -------------------------------------------------------------- Summary: 3 passed, 1 failed, 0 in progress, 1 not in use. Disconnecting from device... Saving result file...
You can also review the details of the test results using a Browser. Open TestApp.xml which can be found in the sample_src directory (based on the output option). By opening the xml file in a web browser the xsl is automatically applied to create html.
Implement Exercises
Now edit the training source code to complete the following exercises:
- Exercise()
- Assignment 1: Add an srNOTE to Exercise() that will add a simple message to the test report (e.g. "Exercise ...")
- Hint: You will probably want to read about Test Macros
- Hint: srTestCaseSetStatus(srTEST_CASE_DEFAULT, srTEST_NOTINUSE, 0) is a placeholder to be removed when you add your test code.
- Assignment 2: Within Exercise() validate that sut_mult(1,1) does NOT equal sut_add(1,1)
- Hint: You will use a Test Macro.
Check Results
- Before you rebuild TestApp.exe, you will need to shut it down by entering 'q' in its console window or closing the window directly.
- After rebuilding, invoke TestApp.exe once again.
- Execute only TestBasic using the stride runner:
> stride --options_file myoptions.txt --run TestBasic
Loading database... Connecting to device... Executing... test unit "TestBasic" > 4 passed, 1 failed, 0 in progress, 0 not in use. -------------------------------------------------------------- Summary: 4 passed, 1 failed, 0 in progress, 0 not in use. Disconnecting from device... Saving result file...
- If you have TestApp.xml already open in your browser, you can simply refresh (F5), to view the latest test results.
Run and Publish Results
When you have completed the Exercise(s) publish your results to Test Space(--space TestBasic). If you have not added test space options to your options file (myoptions.txt) please see testspace access.
> stride --options_file myoptions.txt --run TestBasic --space TestBasic --upload
Loading database... Connecting to device... Executing... test unit "TestBasic" > 4 passed, 1 failed, 0 in progress, 0 not in use. ------------------------------------------------------------ Summary: 4 passed, 1 failed, 0 in progress, 0 not in use. Disconnecting from device... Saving result file... Uploading to test space...
Validate Uploaded Results
Navigate to Test Space using your browser, then validate your results against the pre-configured baseline. For details, please see Confirming Training Exercise Results
Note: This space has been set up with a Baseline of expected test results that you can use to validate your results.
You can view the results on test space by pointing your browser at https://yourcompany.stridetestspace.com. Log in using the credentials you supplied earlier in the options file.
Reference
The following reference information is related to Test Unit basics.
Wiki
- Test Units Overview - Provides a general overview Test Units (i.e. writing tests in C and C++)
- Test Unit Packaging - Discusses the three types of packaging that can be used for Test Units (we prefer Test Classes even for c programmers)
- Test Macros - Optional macros that provide shortcuts for testing assertions and automatic report annotation (you will want to use these).
- Notes - Used to add logging information to your test logic (automatically added to test reports)
- Test Logs - Used to add logging information to your source code (added to test reports if enabled)
- Tracing - The Runner allows tracing on logs and test points.
Samples
- Test Class Sample - Specifically the Basic Simple Test Unit
- Test Macro Sample - This sample covers simple uses of each of the Test Macros.
Note - Other Test Unit Samples related to packaging that are useful are the following: