|
4 | 4 |
|
5 | 5 | Testing is a crucial component of writing quality software and the nature LvArray lends itself nicely to unit tests. |
6 | 6 |
|
7 | | -Building and running the test |
8 | | ------------------------------ |
| 7 | +Building and Running the Tests |
| 8 | +------------------------------ |
9 | 9 | Tests are built by default, to disable the tests set the CMake variable ``ENABLE_TESTS`` to ``OFF``. The tests are output in the ``tests`` folder of the build directory. |
10 | 10 |
|
11 | 11 | To run all the tests run ``make test`` in the build directory. To run a specific set of tests that match the regular expression ``REGEX`` run ``ctest -V -R REGEX``, to run just ``testCRSMatrix`` run ``./tests/testCRSMatrix``. LvArray uses `Google Test`_ for the testing framework and each test accepts a number of command line arguments. |
@@ -73,13 +73,13 @@ The most useful of these is ``gtest_filter`` which lets you run a subset of test |
73 | 73 |
|
74 | 74 | Test structure |
75 | 75 | -------------- |
76 | | -The source for all the tests are all located in the ``unitTests`` directory, each tests consists of a ``cpp`` whose name begins with ``test`` followed by the name of the class or namespace that is tested. For example the tests for ``CRSMatrix`` and ``CRSMatrixView`` are in ``unitTests/testCRSMatrix.cpp`` and the tests for ``sortedArrayManipulation`` are in ``unitTests/testSortedArrayManipulation.cpp``. |
| 76 | +The source for all the tests are all located in the ``unitTests`` directory, each tests consists of a ``cpp`` file whose name begins with ``test`` followed by the name of the class or namespace that is tested. For example the tests for ``CRSMatrix`` and ``CRSMatrixView`` are in ``unitTests/testCRSMatrix.cpp`` and the tests for ``sortedArrayManipulation`` are in ``unitTests/testSortedArrayManipulation.cpp``. |
77 | 77 |
|
78 | 78 | .. note:: |
79 | 79 | The tests for ``LvArray::Array``, ``LvArray::ArrayView`` and ``LvArray::tensorOps`` are spread across multiple ``cpp`` files in order to speed up compilation on multithreaded systems. |
80 | 80 |
|
81 | | -Adding a new test |
82 | | ---------------------- |
| 81 | +Adding a New Test |
| 82 | +----------------- |
83 | 83 | Any time new functionality is added it should be tested. Before writing any test code it is highly recommended you familiarize yourself with the Google Test framework, see the `Google Test primer`_ and `Google Test advanced`_ documentation. |
84 | 84 |
|
85 | 85 | As an example say you add a new class ``Foo`` |
@@ -168,12 +168,11 @@ Best practices |
168 | 168 | - Whenever possible use typed tests. |
169 | 169 | - Whenever possible do not write CUDA (or OpenMP) specific tests. Instead write tests a typed test that is templated on the RAJA policy and use a typed test to instantiate it with the appropriate policies. |
170 | 170 | - When linking to gtest it is not necessary to include the ``main`` function in the executable because if it is not there ``gtest`` will link in its own ``main``. However you should include ``main`` in each test file to ease debugging. Furthermore if the executable needs some setup or cleanup such as initializing MPI it should be done in main. Note that while it is certainly possible to write tests which take command line arguments it is discouraged because then ``./tests/testThatTakesCommandLineArguments`` no longer works. |
171 | | - - For commonly called functions define a macro which first calls ``SCOPED_TRACE`` and then the the function. This helps illuminate exactly where errors are occuring. |
| 171 | + - For commonly called functions define a macro which first calls ``SCOPED_TRACE`` and then the the function. This helps illuminate exactly where errors are occurring. |
172 | 172 | - Prefer the ``EXPECT_`` family of macros to the ``ASSERT_`` family. |
173 | 173 | - Use the most specific ``EXPECT_`` macro applicable. So don't do ``EXPECT_TRUE( bar() == 5 )`` instead use ``EXPECT_EQ( bar(), 5 )`` |
174 | 174 |
|
175 | 175 | .. _`Google Test`: https://github.com/google/googletest/tree/306f3754a71d6d1ac644681d3544d06744914228 |
176 | 176 | .. _`Google Test primer`: https://github.com/google/googletest/blob/306f3754a71d6d1ac644681d3544d06744914228/googletest/docs/primer.md |
177 | 177 | .. _`Google Test advanced`: https://github.com/google/googletest/blob/306f3754a71d6d1ac644681d3544d06744914228/googletest/docs/advanced.md |
178 | 178 | .. _`typed tests`: https://github.com/google/googletest/blob/306f3754a71d6d1ac644681d3544d06744914228/googletest/docs/advanced.md#typed-tests |
179 | | - |
0 commit comments