---
schema_version: "1"
id: 59cd4962ab7de3eb5b1841a946b42bebbc76e0d1b76684e186c0e07236855018
title: Test Apex Code
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/salesforcedx/codebuilder/guides/files/develop/apex/codebuilder-apex-tests.md
canonical_url: https://developer.salesforce.com/docs/platform/code-builder/guide/codebuilder-apex-tests.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: f47ceaddc0fbccc7cfdd9042c4e8958f3a98c4ab0d2d1a662ec531d690516960
products:
  - Agentforce Vibes IDE
  - salesforcedx
---
# Test Apex Code

The Apex extension allows you to run Apex tests to verify the functionality of your code.

## Explore Your Apex Tests

To access the test view, click the beaker icon ( ![beaker icon](https://developer.salesforce.com/media/vscode/beaker-icon-16.png '{"class": "image-icon-sm"}') ) in the Activity Bar on the left side of the VS Code editor. If you don’t see this icon, make sure that the project contains an `sfdx-project.json` file in its root directory.

Use the Apex Tests feature to run one test method, test methods in one class, or all your Apex tests.

The Apex extension allows you to run Apex tests to verify the functionality of your code.

## Explore Your Apex Tests

To access the test view, click the beaker icon (![beaker icon](https://developer.salesforce.com/docs/platform/media/shared/beaker-icons-16.png '{"class": "image-icon-sm"}')) in the Activity Bar on the left side of the VS Code editor. If you don’t see this icon, make sure that the project contains a `sfdx-project.json` file in its root directory.

Use the Apex Tests feature to run one test method, test methods in one class, or all your Apex tests.

### Run Tests

- Run a test for a single method: Hover over the name of a test method and click the play icon.
- Run tests for all the methods in a class: Hover over the name of a test class and click the play icon.
- Run all tests: Hover over the Apex Tests view and click the play icon.

After you run Apex tests, **SFDX: Re-Run Last Invoked Apex Test Class** and **SFDX: Re-Run Last Invoked Apex Test Method** commands are available in the Command Palette.

### View Test Results

- For passing tests, the blue icons next to the classes and methods change to green icons.
- For failing tests, the icons turn red.

To see the details of your test runs, hover over the name of a test class in the Side Bar.
The results of the test are displayed in the Output panel.

### Go to Test Class Definitions

To jump to the definition of a test class, a test method that passed, or a method that you haven’t run yet, click its name. If you click the name of a failed test method, you jump to the line where the failure occurred.

### Clear Test Results

To clear the test results, click the refresh icon at the top of the Apex Tests view.

### Refresh Apex Tests View

If you've added methods or classes since the last time the Test view was populated, click the refresh icon at the top of the Apex Tests view for the updated list.

## Run Apex Tests from Within a File

You can run Apex tests from the class file open in the editor window. Click **Run Test** above the definition of an Apex test method or **Run All Tests** above the definition of an Apex test class. You can view the test results in the Output panel and the Failures section of the output lists stack traces for failed tests. To navigate to the line of code that caused a failure, press Ctrl (Windows or Linux) or Cmd (macOS) and click that stack trace.

![Running Apex tests using the Run Test and Run All Tests code lenses](https://developer.salesforce.com/docs/platform/media/shared/apex_test_run.gif '{"class": "image-lg"}')

### Highlight Apex Test Code Coverage

You can retrieve code coverage results for your Apex classes and Apex triggers every time you run one or more tests. To do this, [edit your workspace settings](https://code.visualstudio.com/docs/getstarted/settings) and check `retrieve-test-code-coverage` and then run your Apex tests. You can now see the code coverage in the Output panel, which shows the coverage percentage per Apex class and Apex trigger and lines that aren't covered by the test run results.

![Apex test results with code coverage](https://developer.salesforce.com/docs/platform/media/shared/code_coverage_output.png '{"class": "image-lg"}')

To see code coverage for your test, click the three-bars icon that’s next to your Org alias at the bottom of the Side Bar and open the Apex Class or Apex Trigger being tested. Click the three-bars icon to toggle between enabling and disabling code coverage highlighting.

![Enable Apex test visual code coverage](https://developer.salesforce.com/docs/platform/media/shared/code_coverage_footer2.png '{"class": "image-lg"}')

![Apex test visual code coverage demo](https://developer.salesforce.com/docs/platform/media/shared/code_coverage_demo.gif '{"class": "image-lg"}')

### See Also

_Apex Developer Guide_: [Testing Apex](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing.htm)

