| 1 |
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments. |
| 2 |
|
| 3 |
# ctest |
| 4 |
|
| 5 |
azure-ctest is a simple portable C test runner. |
| 6 |
|
| 7 |
## Setup |
| 8 |
|
| 9 |
1. Clone **azure-ctest** by: |
| 10 |
|
| 11 |
``` |
| 12 |
git clone https://github.com/Azure/azure-ctest |
| 13 |
``` |
| 14 |
|
| 15 |
2. Create a folder called *cmake* (or any name of your choice). |
| 16 |
|
| 17 |
3. Switch to the *cmake* folder and run |
| 18 |
``` |
| 19 |
cmake .. |
| 20 |
``` |
| 21 |
|
| 22 |
### Build |
| 23 |
|
| 24 |
Switch to the *cmake* folder and run: |
| 25 |
|
| 26 |
``` |
| 27 |
cmake --build . |
| 28 |
``` |
| 29 |
|
| 30 |
### Installation and Use |
| 31 |
Optionally, you may choose to install azure-ctest on your machine: |
| 32 |
|
| 33 |
1. Switch to the *cmake* folder and run |
| 34 |
``` |
| 35 |
cmake --build . --target install |
| 36 |
``` |
| 37 |
or |
| 38 |
|
| 39 |
Linux: |
| 40 |
``` |
| 41 |
sudo make install |
| 42 |
``` |
| 43 |
|
| 44 |
Windows: |
| 45 |
``` |
| 46 |
msbuild /m INSTALL.vcxproj |
| 47 |
``` |
| 48 |
|
| 49 |
2. Use it in your project (if installed) |
| 50 |
``` |
| 51 |
find_package(ctest REQUIRED CONFIG) |
| 52 |
target_link_library(yourlib ctest) |
| 53 |
``` |
| 54 |
|
| 55 |
### Building the tests |
| 56 |
|
| 57 |
In order to build the tests use the *run_unittests* cmake option: |
| 58 |
|
| 59 |
``` |
| 60 |
cmake .. -Drun_unittests:bool=ON |
| 61 |
``` |
| 62 |
|
| 63 |
## Example |
| 64 |
|
| 65 |
```c |
| 66 |
#include "ctest.h" |
| 67 |
#include "SomeUnitUnderTest.h" |
| 68 |
|
| 69 |
CTEST_BEGIN_TEST_SUITE(SimpleTestSuiteOneTest) |
| 70 |
|
| 71 |
CTEST_FUNCTION(Test1) |
| 72 |
{ |
| 73 |
// arrange |
| 74 |
|
| 75 |
// act |
| 76 |
int x = SomeFunction(); |
| 77 |
|
| 78 |
// assert |
| 79 |
CTEST_ASSERT_ARE_EQUAL(int, 42, x); |
| 80 |
} |
| 81 |
|
| 82 |
CTEST_END_TEST_SUITE(SimpleTestSuiteOneTest) |
| 83 |
``` |