> For the complete documentation index, see [llms.txt](https://knowledgebase.autorabit.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://knowledgebase.autorabit.com/product-guides/codescan/codescan-integration/codescan-sfdx-plugin/importing-code-coverage-from-sfdx-projects.md).

# Importing Code Coverage from SFDX projects

CodeScan now provides a way to view your unit test coverage from your SFDX projects in SonarQube™.

### Requirements <a href="#requirements" id="requirements"></a>

* A working **SonarQube™ 9.9+ LTA** installation
* A licensed [**CodeScan**](https://www.codescan.io/) **(4.1+) plugin**
* An **SFDX** project linked to your Salesforce Org

### Configuration <a href="#configuration" id="configuration"></a>

Run your tests in your org using ***sfdx force:apex:test:run*** and the following parameters:

* ***-c*** This is to return code coverage
* ***-d .*** This is to define the output directory. In this case the current directory (.).
* ***-u your-username*** This is the username or alias of the org you would like to run tests in.
* ***-r json*** This defines the output type as a JSON file.

The end command should look something like as below, run this command:

```
sfdx force:apex:test:run -c -d . -u username -r json
```

If all goes with the plan, you should find a **JSON file** in your project’s directory named this as ***test-result-TESTRUNID.json*** where ***TESTRUNID*** is the ID of your test run.

In order to import this into **SonarQube™**, pass the parameter ***sf.testfile*** with your build.\
For the file you have just created in the root folder of your project, you will need to pass ***sf.testfile=test-result-TESTRUNID.json***.

If you have created the test file somewhere else, you will need to provide the path relative to the root folder of your project.

With the coverage being imported, the full analysis command will look something like this:

{% code overflow="wrap" %}

```
sfdx codescan:run --token <token> --projectkey my-project-key --organization my-org-key -Dsf.testfile=test-result-TESTRUNID.json
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://knowledgebase.autorabit.com/product-guides/codescan/codescan-integration/codescan-sfdx-plugin/importing-code-coverage-from-sfdx-projects.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
