New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CMake: Add separate unit test targets #660
Conversation
Each unit test file ClassName.cpp, which results in the creation of a test target openshot-ClassName-test, will now also be labeled with the CTest label ClassName, and a target ClassName_coverage will be generated that runs only the tests in that file. This is especially useful when developing tests for a class, as the tests in the class being worked on can be re-run without having to wait a minute or more while the other tests run.
In fact, the labeling has an unexpected side benefit: This summary, which CTest displays at the end of the run if the full suite of tests are enabled:
So we can now see at a glance that The long runtime may simply be a result of test thoroughness and/or complexity. (That's certainly why |
Codecov Report
@@ Coverage Diff @@
## develop #660 +/- ##
========================================
Coverage 52.42% 52.42%
========================================
Files 151 151
Lines 12346 12346
========================================
Hits 6473 6473
Misses 5873 5873
Continue to review full report at Codecov.
|
Merging this, as it's relatively inconsequential unless used. (Except for a switch I snuck in, to use the standard CTest variable |
Each unit test file
ClassName.cpp
, which results in the creation of a test targetopenshot-ClassName-test
, will now also be labeled with the CTest labelClassName
, and a targetClassName_coverage
will be generated that runs only the tests in that file.The names
Just like the main
coverage
target, the target nameClassName_coverage
is just a generic name. Running the target will collect coverage data ifENABLE_COVERAGE
is set, but will run the tests without coverage if it is left disabled. It does not imply collection of coverage data.(That all started because I couldn't redefine the
test
target to also collect coverage, so I had to use a different name. And since it's easier to always use the same target name, I madecoverage
work to run tests with or withoutENABLE_COVERAGE
. I could have called the individual targetsClassName_test
, but I decided to be consistent withcoverage
.)Y THO?
The separate targets are especially useful when developing tests for a class, as the tests in the class being worked on can be re-run without having to wait a minute or more while the other tests run.
Example workflow
(The first time through, libopenshot itself will still have to be built before the tests can run. But in subsequent executions of
cmake --build build --target MyClass_coverage
, the build will be quick because the only file that will be recompiled istests/MyClass.cpp
. When running the tests, the very lengthy runtimes of certain tests inFrameMapper
,FFmpegWriter
, andCVTracker
are avoided.)