blob: e5cd211209f239f5382aff71f4c7c0a5ee762137 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>FIXTURES_REQUIRED &mdash; CMake 3.8.2 Documentation</title>
<link rel="stylesheet" href="../_static/cmake.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '3.8.2',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="shortcut icon" href="../_static/cmake-favicon.ico"/>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="FIXTURES_SETUP" href="FIXTURES_SETUP.html" />
<link rel="prev" title="FIXTURES_CLEANUP" href="FIXTURES_CLEANUP.html" />
</head>
<body role="document">
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="FIXTURES_SETUP.html" title="FIXTURES_SETUP"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="FIXTURES_CLEANUP.html" title="FIXTURES_CLEANUP"
accesskey="P">previous</a> |</li>
<li>
<img src="../_static/cmake-logo-16.png" alt=""
style="vertical-align: middle; margin-top: -2px" />
</li>
<li>
<a href="https://cmake.org/">CMake</a> &#187;
</li>
<li>
<a href="../index.html">3.8.2 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="../manual/cmake-properties.7.html" accesskey="U">cmake-properties(7)</a> &#187;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="fixtures-required">
<span id="prop_test:FIXTURES_REQUIRED"></span><h1>FIXTURES_REQUIRED<a class="headerlink" href="#fixtures-required" title="Permalink to this headline">ΒΆ</a></h1>
<p>Specifies a list of fixtures the test requires. Fixture names are case
sensitive.</p>
<p>Fixtures are a way to attach setup and cleanup tasks to a set of tests. If a
test requires a given fixture, then all tests marked as setup tasks for that
fixture will be executed first (once for the whole set of tests, not once per
test requiring the fixture). After all tests requiring a particular fixture
have completed, CTest will ensure all tests marked as cleanup tasks for that
fixture are then executed. Tests are marked as setup tasks with the
<span class="target" id="index-0-prop_test:FIXTURES_SETUP"></span><a class="reference internal" href="FIXTURES_SETUP.html#prop_test:FIXTURES_SETUP" title="FIXTURES_SETUP"><code class="xref cmake cmake-prop_test docutils literal"><span class="pre">FIXTURES_SETUP</span></code></a> property and as cleanup tasks with the
<span class="target" id="index-0-prop_test:FIXTURES_CLEANUP"></span><a class="reference internal" href="FIXTURES_CLEANUP.html#prop_test:FIXTURES_CLEANUP" title="FIXTURES_CLEANUP"><code class="xref cmake cmake-prop_test docutils literal"><span class="pre">FIXTURES_CLEANUP</span></code></a> property. If any of a fixture&#8217;s setup tests fail,
all tests listing that fixture in their <code class="docutils literal"><span class="pre">FIXTURES_REQUIRED</span></code> property will not
be executed. The cleanup tests for the fixture will always be executed, even if
some setup tests fail.</p>
<p>When CTest is asked to execute only a subset of tests (e.g. by the use of
regular expressions or when run with the <code class="docutils literal"><span class="pre">--rerun-failed</span></code> command line
option), it will automatically add any setup or cleanup tests for fixtures
required by any of the tests that are in the execution set.</p>
<p>Since setup and cleanup tasks are also tests, they can have an ordering
specified by the <span class="target" id="index-0-prop_test:DEPENDS"></span><a class="reference internal" href="DEPENDS.html#prop_test:DEPENDS" title="DEPENDS"><code class="xref cmake cmake-prop_test docutils literal"><span class="pre">DEPENDS</span></code></a> test property just like any other tests.
This can be exploited to implement setup or cleanup using multiple tests for a
single fixture to modularise setup or cleanup logic.</p>
<p>The concept of a fixture is different to that of a resource specified by
<span class="target" id="index-0-prop_test:RESOURCE_LOCK"></span><a class="reference internal" href="RESOURCE_LOCK.html#prop_test:RESOURCE_LOCK" title="RESOURCE_LOCK"><code class="xref cmake cmake-prop_test docutils literal"><span class="pre">RESOURCE_LOCK</span></code></a>, but they may be used together. A fixture defines a
set of tests which share setup and cleanup requirements, whereas a resource
lock has the effect of ensuring a particular set of tests do not run in
parallel. Some situations may need both, such as setting up a database,
serialising test access to that database and deleting the database again at the
end. For such cases, tests would populate both <code class="docutils literal"><span class="pre">FIXTURES_REQUIRED</span></code> and
<span class="target" id="index-1-prop_test:RESOURCE_LOCK"></span><a class="reference internal" href="RESOURCE_LOCK.html#prop_test:RESOURCE_LOCK" title="RESOURCE_LOCK"><code class="xref cmake cmake-prop_test docutils literal"><span class="pre">RESOURCE_LOCK</span></code></a> to combine the two behaviours. Names used for
<span class="target" id="index-2-prop_test:RESOURCE_LOCK"></span><a class="reference internal" href="RESOURCE_LOCK.html#prop_test:RESOURCE_LOCK" title="RESOURCE_LOCK"><code class="xref cmake cmake-prop_test docutils literal"><span class="pre">RESOURCE_LOCK</span></code></a> have no relationship with names of fixtures, so note
that a resource lock does not imply a fixture and vice versa.</p>
<p>Consider the following example which represents a database test scenario
similar to that mentioned above:</p>
<div class="highlight-cmake"><div class="highlight"><pre><span></span><span class="nb">add_test</span><span class="p">(</span><span class="s">NAME</span> <span class="s">testsDone</span> <span class="s">COMMAND</span> <span class="s">emailResults</span><span class="p">)</span>
<span class="nb">add_test</span><span class="p">(</span><span class="s">NAME</span> <span class="s">fooOnly</span> <span class="s">COMMAND</span> <span class="s">testFoo</span><span class="p">)</span>
<span class="nb">add_test</span><span class="p">(</span><span class="s">NAME</span> <span class="s">dbOnly</span> <span class="s">COMMAND</span> <span class="s">testDb</span><span class="p">)</span>
<span class="nb">add_test</span><span class="p">(</span><span class="s">NAME</span> <span class="s">dbWithFoo</span> <span class="s">COMMAND</span> <span class="s">testDbWithFoo</span><span class="p">)</span>
<span class="nb">add_test</span><span class="p">(</span><span class="s">NAME</span> <span class="s">createDB</span> <span class="s">COMMAND</span> <span class="s">initDB</span><span class="p">)</span>
<span class="nb">add_test</span><span class="p">(</span><span class="s">NAME</span> <span class="s">setupUsers</span> <span class="s">COMMAND</span> <span class="s">userCreation</span><span class="p">)</span>
<span class="nb">add_test</span><span class="p">(</span><span class="s">NAME</span> <span class="s">cleanupDB</span> <span class="s">COMMAND</span> <span class="s">deleteDB</span><span class="p">)</span>
<span class="nb">add_test</span><span class="p">(</span><span class="s">NAME</span> <span class="s">cleanupFoo</span> <span class="s">COMMAND</span> <span class="s">removeFoos</span><span class="p">)</span>
<span class="nb">set_tests_properties</span><span class="p">(</span><span class="s">setupUsers</span> <span class="s">PROPERTIES</span> <span class="s">DEPENDS</span> <span class="s">createDB</span><span class="p">)</span>
<span class="nb">set_tests_properties</span><span class="p">(</span><span class="s">createDB</span> <span class="s">PROPERTIES</span> <span class="s">FIXTURES_SETUP</span> <span class="s">DB</span><span class="p">)</span>
<span class="nb">set_tests_properties</span><span class="p">(</span><span class="s">setupUsers</span> <span class="s">PROPERTIES</span> <span class="s">FIXTURES_SETUP</span> <span class="s">DB</span><span class="p">)</span>
<span class="nb">set_tests_properties</span><span class="p">(</span><span class="s">cleanupDB</span> <span class="s">PROPERTIES</span> <span class="s">FIXTURES_CLEANUP</span> <span class="s">DB</span><span class="p">)</span>
<span class="nb">set_tests_properties</span><span class="p">(</span><span class="s">cleanupFoo</span> <span class="s">PROPERTIES</span> <span class="s">FIXTURES_CLEANUP</span> <span class="s">Foo</span><span class="p">)</span>
<span class="nb">set_tests_properties</span><span class="p">(</span><span class="s">testsDone</span> <span class="s">PROPERTIES</span> <span class="s">FIXTURES_CLEANUP</span> <span class="s2">&quot;DB;Foo&quot;</span><span class="p">)</span>
<span class="nb">set_tests_properties</span><span class="p">(</span><span class="s">fooOnly</span> <span class="s">PROPERTIES</span> <span class="s">FIXTURES_REQUIRED</span> <span class="s">Foo</span><span class="p">)</span>
<span class="nb">set_tests_properties</span><span class="p">(</span><span class="s">dbOnly</span> <span class="s">PROPERTIES</span> <span class="s">FIXTURES_REQUIRED</span> <span class="s">DB</span><span class="p">)</span>
<span class="nb">set_tests_properties</span><span class="p">(</span><span class="s">dbWithFoo</span> <span class="s">PROPERTIES</span> <span class="s">FIXTURES_REQUIRED</span> <span class="s2">&quot;DB;Foo&quot;</span><span class="p">)</span>
<span class="nb">set_tests_properties</span><span class="p">(</span><span class="s">dbOnly</span> <span class="s">dbWithFoo</span> <span class="s">createDB</span> <span class="s">setupUsers</span> <span class="s">cleanupDB</span>
<span class="s">PROPERTIES</span> <span class="s">RESOURCE_LOCK</span> <span class="s">DbAccess</span><span class="p">)</span>
</pre></div>
</div>
<p>Key points from this example:</p>
<ul class="simple">
<li>Two fixtures are defined: <code class="docutils literal"><span class="pre">DB</span></code> and <code class="docutils literal"><span class="pre">Foo</span></code>. Tests can require a single
fixture as <code class="docutils literal"><span class="pre">fooOnly</span></code> and <code class="docutils literal"><span class="pre">dbOnly</span></code> do, or they can depend on multiple
fixtures like <code class="docutils literal"><span class="pre">dbWithFoo</span></code> does.</li>
<li>A <code class="docutils literal"><span class="pre">DEPENDS</span></code> relationship is set up to ensure <code class="docutils literal"><span class="pre">setupUsers</span></code> happens after
<code class="docutils literal"><span class="pre">createDB</span></code>, both of which are setup tests for the <code class="docutils literal"><span class="pre">DB</span></code> fixture and will
therefore be executed before the <code class="docutils literal"><span class="pre">dbOnly</span></code> and <code class="docutils literal"><span class="pre">dbWithFoo</span></code> tests
automatically.</li>
<li>No explicit <code class="docutils literal"><span class="pre">DEPENDS</span></code> relationships were needed to make the setup tests run
before or the cleanup tests run after the regular tests.</li>
<li>The <code class="docutils literal"><span class="pre">Foo</span></code> fixture has no setup tests defined, only a single cleanup test.</li>
<li><code class="docutils literal"><span class="pre">testsDone</span></code> is a cleanup test for both the <code class="docutils literal"><span class="pre">DB</span></code> and <code class="docutils literal"><span class="pre">Foo</span></code> fixtures.
Therefore, it will only execute once regular tests for both fixtures have
finished (i.e. after <code class="docutils literal"><span class="pre">fooOnly</span></code>, <code class="docutils literal"><span class="pre">dbOnly</span></code> and <code class="docutils literal"><span class="pre">dbWithFoo</span></code>). No
<code class="docutils literal"><span class="pre">DEPENDS</span></code> relationship was specified for <code class="docutils literal"><span class="pre">testsDone</span></code>, so it is free to
run before, after or concurrently with other cleanup tests for either
fixture.</li>
<li>The setup and cleanup tests never list the fixtures they are for in their own
<code class="docutils literal"><span class="pre">FIXTURES_REQUIRED</span></code> property, as that would result in a dependency on
themselves and be considered an error.</li>
</ul>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h4>Previous topic</h4>
<p class="topless"><a href="FIXTURES_CLEANUP.html"
title="previous chapter">FIXTURES_CLEANUP</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="FIXTURES_SETUP.html"
title="next chapter">FIXTURES_SETUP</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/prop_test/FIXTURES_REQUIRED.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="FIXTURES_SETUP.html" title="FIXTURES_SETUP"
>next</a> |</li>
<li class="right" >
<a href="FIXTURES_CLEANUP.html" title="FIXTURES_CLEANUP"
>previous</a> |</li>
<li>
<img src="../_static/cmake-logo-16.png" alt=""
style="vertical-align: middle; margin-top: -2px" />
</li>
<li>
<a href="https://cmake.org/">CMake</a> &#187;
</li>
<li>
<a href="../index.html">3.8.2 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="../manual/cmake-properties.7.html" >cmake-properties(7)</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2000-2017 Kitware, Inc. and Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.2.
</div>
</body>
</html>