# Step 3: Connect Tests

## Add Script in CI Pipeline to Connect Tests

Need to add an executable script in the CI to call the TestBrain API with the test conditions.

## Requirements

* Required: **Python 3.7+**

## Installation Command

```
--pip install appsurifyci --upgrade
```

## Available Arguments

| Argument                  | Options                                                                                                                                                                                                                                      |
| ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--runtestswithappsurify` | Call to Appsurify TestBrain API                                                                                                                                                                                                              |
| --`apikey`                | <p>API Key from Appsurify Instance. Found in top right hand corner drop-down menu.<br>Can be stored as a Secret in CI server secret storage capabilities.<br>Reference the Secret via variable Script execution in the CI configuration.</p> |
| `--url`                   | Url of Appsurify Instance i.e., <https://dummy.appsurify.com/>                                                                                                                                                                               |
| `--project`               | Name of the project                                                                                                                                                                                                                          |
| `--testsuite`             | Name of the Test Suite                                                                                                                                                                                                                       |
| `--branch`                | Name of the branch the tests are running against                                                                                                                                                                                             |
| `--commit`                | SHA of the commit (need full SHA)                                                                                                                                                                                                            |

## Recommended Arguments

| Argument         | Options                                                                                                                                                                                                                                                       |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--runtemplate`  | <p>Options - <strong>all tests, no tests, prioritized tests</strong>.<br><strong>See below for more details.</strong> </p>                                                                                                                                    |
| `--testtemplate` | <p>Options - mvn, pytest, cypress, mocha, mstest, vstest, opentest...etc. <br><br>See Integrations for more supported Test Frameworks</p>                                                                                                                     |
| `--runcommand`   | <p>Command to execute tests in the target environment, if command is custom to your test suite. <br><br>Note, <code>--runcommand</code> will override generic <code>--testtemplate</code> at time of final configuration and prioritized test execution. </p> |
| `--report`       | Location of XML reports created by the test run if this is not the default location for the test type.                                                                                                                                                        |
| `--pipeoutput`   | Additional logging is printed to the screen from the Test Execution runner to help with Debugging and Logs                                                                                                                                                    |

## Test Execution Parameters

|                       |                                                                                                                                                                        |
| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--all tests`         | <p>Will run all tests. Will fail on any failure.<br>Recommended for nightly or weekly test executions. <br><br><strong>Recommended for Appsurify to Learn</strong></p> |
| `--no tests`          | <p>Will run no tests. Will fail on any failure.<br>Recommended when starting with Appsurify to just upload data. </p>                                                  |
| `--prioritized tests` | <p>Requires the Percentage or Time based Argument.<br><br>Will fail the build on new / re-opened defects.<br><br>Predictive Test Selection Technology<br></p>          |

## Example

```
--runtestswithappsurify --url "https://ABC.appsurify.com" --apikey "api key" --project "project" --testsuite "testsuite" --runtemplate "all tests" --runcommand "mvn" --commit "commit id" --branch "branch" --report "report" --pipeout "true"
```

## Example in CI Pipeline

```
--runtestwithappsurify --url "https://testbraindemo.appsurify.com" --apikey "NTk6cD1Ua3doV3uNDMdWzz" --project "TestBrainDemoJunit" --testsuite "Selenium" --runtemplate "all tests" --runcommand "mvn" --commit "commit id" --branch "branch" --report "report" --pipeoutput "true"
```

## Confirmation: Test Bind Turns Green

Upon successful Test Connection, in your Summary Page - your Test Bind Icon turns <mark style="color:green;">Green</mark>.&#x20;

<figure><img src="/files/KtOB72lXSLTJLgU2d0J6" alt="appsurify test bind connection successful"><figcaption></figcaption></figure>

## Push tests as part of CI process to build Model Maturity

Now that you've successfully Connected your Tests, automate them as part of the CI build process  to build the Model Maturity wheel. \
\
Depending on how many Test Runs per day, this could take \~2-3 weeks. AKA, the more test data / runs - the stronger the results!&#x20;

Once Model Maturity wheel has hit 50 Test runs or 100%, your Model will be trained over the following weekend, and will be subsequently ready for Predictive Test Selection mode - and your team can begin to enjoy the time and resource savings!&#x20;

## Additional Arguments - For Customization

<table><thead><tr><th width="268">Argument</th><th width="188.33333333333331">Default</th><th>Options / Details</th></tr></thead><tbody><tr><td><code>--fail</code></td><td><code>newdefects</code><br><code>reopeneddefects</code></td><td>Options: <code>newdefects, reopeneddefects, flakybrokentests, newflaky, reopenedflaky, failedtests, brokentests</code></td></tr><tr><td><code>--rerun</code></td><td>"false"</td><td>whether failed tests should be rerun</td></tr><tr><td><code>--maxrerun</code></td><td>3</td><td>the number of times failed tests should be rerun</td></tr><tr><td><code>--failfast</code></td><td>"false"</td><td>whether after each set of tests runs to determine if the build has failed (tests will still be rerun if this has been selected)</td></tr><tr><td><code>--executioncommand</code></td><td>" "</td><td>command to be executed following completion of the script [[teststorun]] will be replaced with the formatted list of tests to run</td></tr><tr><td><code>--percentage</code></td><td>" "</td><td>Percentage based prioritized test selection and execution. <strong>RECOMMENDED</strong> to start ~30%. <br><br>Example: <br><code>--percentage "20"</code> would run top 20% of tests most likely to fail. </td></tr><tr><td><code>--time</code></td><td>" " </td><td>Time based prioritized test execution. <br><br>Example: <br>--time "45s" would run top 45 seconds of tests most likely to fail.<br><br>Example<br>--time "10m" would run top 10 minutes of tests most likely to fail. </td></tr></tbody></table>

## Next: [Start Test Prioritization](/getting-started/start-prioritized-testing.md)!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.appsurify.com/getting-started/step-3-connect-tests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
