docs/versions/7.4.0/rules/lib/toplevel/testing.mdx
{% dynamic setvar source_file "src/main/java/com/google/devtools/build/lib/starlarkbuildapi/test/TestingModuleApi.java" %} {% dynamic setvar version "7.4.0" %} {% dynamic setvar original_path "/rules/lib/toplevel/testing" %} {% include "_buttons.html" %}
<!-- {% raw %} -->Helper methods for Starlark to access testing infrastructure.
<h2>Members</h2> <ul> <li> <a href="#analysis_test">analysis_test</a> </li> <li> <a href="#ExecutionInfo">ExecutionInfo</a> </li> <li> <a href="#TestEnvironment">TestEnvironment</a> </li> </ul> <h2 id="analysis_test">analysis_test</h2>
<p><pre class="rule-signature"><code>None</code> testing.analysis_test(name, implementation, attrs={}, fragments=[], toolchains=[], attr_values={})</pre></p>
Creates a new analysis test target. <p>The number of transitive dependencies of the test are limited. The limit is controlled by <code>--analysis_testing_deps_limit</code> flag.
<!-- hide-from-toc is a class used by DevSite for the public Bazel site
(https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
<h3 class="hide-from-toc">Parameters</h3>
<table class="table table-bordered table-condensed table-params">
<colgroup>
<col class="col-param">
<col class="param-description">
</colgroup>
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td id="analysis_test.name">
<code>name</code>
</td>
<td>
required
Name of the target. It should be a Starlark identifier, matching pattern '[A-Za-z_][A-Za-z0-9_]*'.
</td>
</tr>
<tr>
<td id="analysis_test.implementation">
<code>implementation</code>
</td>
<td>
required
The Starlark function implementing this analysis test. It must have exactly one parameter: <a href="../builtins/ctx.html">ctx</a>. The function is called during the analysis phase. It can access the attributes declared by <code>attrs</code> and populated via <code>attr_values</code>. The implementation function may not register actions. Instead, it must register a pass/fail result via providing <a href='../providers/AnalysisTestResultInfo.html'>AnalysisTestResultInfo</a>.
</td>
</tr>
<tr>
<td id="analysis_test.attrs">
<code>attrs</code>
</td>
<td>
<a class="anchor" href="../core/dict.html">dict</a>;
default is <code>{}</code>
Dictionary declaring the attributes. See the <a href="../globals/bzl.html#rule">rule</a> call. Attributes are allowed to use configuration transitions defined using <a href="../globals/bzl.html#analysis_test_transition">analysis_test_transition</a>.
</td>
</tr>
<tr>
<td id="analysis_test.fragments">
<code>fragments</code>
</td>
<td>
<a class="anchor" href="../core/list.html">sequence</a> of <a class="anchor" href="../core/string.html">string</a>s;
default is <code>[]</code>
List of configuration fragments that are available to the implementation of the analysis test.
</td>
</tr>
<tr>
<td id="analysis_test.toolchains">
<code>toolchains</code>
</td>
<td>
<a class="anchor" href="../core/list.html">sequence</a>;
default is <code>[]</code>
The set of toolchains the test requires. See the <a href="../globals/bzl.html#rule">rule</a> call.
</td>
</tr>
<tr>
<td id="analysis_test.attr_values">
<code>attr_values</code>
</td>
<td>
<a class="anchor" href="../core/dict.html">dict</a> of <a class="anchor" href="../core/string.html">string</a>s;
default is <code>{}</code>
Dictionary of attribute values to pass to the implementation.
</td>
</tr>
</tbody>
</table>
<h2 id="ExecutionInfo">ExecutionInfo</h2>
<p><pre class="rule-signature"><a class="anchor" href="../providers/ExecutionInfo.html">ExecutionInfo</a> testing.ExecutionInfo(requirements={}, exec_group='test')</pre></p>
<a href='../providers/ExecutionInfo.html'>testing.ExecutionInfo</a> provider key/constructor
<h2 id="TestEnvironment">TestEnvironment</h2>
<p><pre class="rule-signature"><a class="anchor" href="../providers/RunEnvironmentInfo.html">RunEnvironmentInfo</a> testing.TestEnvironment(environment, inherited_environment=[])</pre></p>
<b>Deprecated: Use RunEnvironmentInfo instead.</b> Creates a new test environment provider. Use this provider to specify extra environment variables to be made available during test execution.
<!-- hide-from-toc is a class used by DevSite for the public Bazel site
(https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
<h3 class="hide-from-toc">Parameters</h3>
<table class="table table-bordered table-condensed table-params">
<colgroup>
<col class="col-param">
<col class="param-description">
</colgroup>
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td id="TestEnvironment.environment">
<code>environment</code>
</td>
<td>
required
A map of string keys and values that represent environment variables and their values. These will be made available during the test execution.
</td>
</tr>
<tr>
<td id="TestEnvironment.inherited_environment">
<code>inherited_environment</code>
</td>
<td>
<a class="anchor" href="../core/list.html">sequence</a> of <a class="anchor" href="../core/string.html">string</a>s;
default is <code>[]</code>
A sequence of names of environment variables. These variables are made available during the test execution with their current value taken from the shell environment. If a variable is contained in both <code>environment</code> and <code>inherited_environment</code>, the value inherited from the shell environment will take precedence if set.
</td>
</tr>
</tbody>
</table>