Code coverage is a valuable metric in CodeScene that helps teams assess the effectiveness of their tests by showing which parts of the codebase are exercised during test execution. If you’re having trouble getting code coverage data to appear or behave as expected in CodeScene, follow these steps to troubleshoot the most common issues.
1. Run the CLI Tool from the Project Root
Make sure you're invoking the CodeScene CLI (cs-coverage
) from the root directory of your project. The CLI expects to find the Git metadata in this location and automatically fetches it to match the project in CodeScene.
Tip: If the CLI fails to locate the project metadata, it may silently fail to associate the coverage data correctly.
2. Ensure Environment Variables Are Properly Set
CodeScene’s CLI requires certain environment variables to authenticate and connect to your CodeScene instance. Make sure the following are correctly set:
- Cloud:
- CS_ACCESS_TOKEN
- For full setup instructions, see the Client Setup Guide.
- CS_ACCESS_TOKEN
- On-prem:
- CS_ONPREM_URL
- CS_ACCESS_TOKEN
- For full setup instructions, see the Client Setup Guide.
3. Match Branch and Commit
The code coverage data must be uploaded for the same branch and commit that CodeScene analyzes. If there’s a mismatch, CodeScene won’t be able to associate the coverage data with the corresponding analysis.
Run
git rev-parse HEAD
in your local repo and compare it to the commit hash in the CodeScene analysis UI.
4. Ensure Matching Repository URL
If you’re generating coverage locally, the Git remote URL used to clone the repo must exactly match the one configured in CodeScene.
This ensures consistent Git metadata between your local environment and the CodeScene project.
5. Trigger a New Analysis After Upload
CodeScene only picks up new code coverage data during an analysis run. After uploading coverage data with the CLI, make sure to trigger a new analysis in CodeScene manually or via the API.
6. Verify What Has Been Uploaded
Use CodeScene’s REST API to confirm that your coverage data was received and parsed correctly.
Refer to the List Data section (Cloud or On-prem) of the documentation to:
-
Check what coverage files are available.
-
Ensure the data is linked to the correct branch and commit.
Need More Help?
If you’ve gone through all these steps and are still experiencing issues, feel free to contact our support team with the following information:
-
Output from the CLI tool
-
Commit hash and branch name
-
Your CodeScene project name
-
Any relevant logs or screenshots
- Code coverage report, if possible