specify dependencies between add_test tests?

Is there a way to explicitly specify the order of execution for ctest tests added with add_test? Specifically, I have one test that generates output which is required as input by two subsequent tests.

It looks like there may be a way to use add_custom_target(...) but I haven’t flushed that out yet. AFAIK, add_test does not create targets so maybe one add_custom_target call for each test with the DEPENDS option … that seems a bit like a kludge.

Thank you.

You need test properties to enforce the kind of behavior you’re after. Take a look at the FIXTURES_SETUP and FIXTURES_REQUIRED test properties (start with the docs for the latter). They allow you to specify that one or more tests need some other test(s) to run first. For completeness, there’s also FIXTURES_CLEANUP.

1 Like

I forgot I also wrote a more detailed article describing the feature here: https://crascit.com/2016/10/18/test-fixtures-with-cmake-ctest/

1 Like

Thank you. That worked perfectly. :+1: