forcedotcom / cli

Salesforce CLI
https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/
BSD 3-Clause "New" or "Revised" License
494 stars 78 forks source link

Missing covarage information #2698

Closed sgozansky closed 9 months ago

sgozansky commented 9 months ago

Hi working on mac M1 - @salesforce/cli/2.26.10 darwin-arm64 node-v18.17.1

running > sf apex run test --tests -ycv --result-format json on test from deployed package. receiving results without coverage status:

"coverage": { "coverage": [], "records": [], "summary": { "totalLines": 0, "coveredLines": 0, "orgWideCoverage": "0%", "testRunCoverage": "0%" } Any idea why there isn't any coverage information?

github-actions[bot] commented 9 months ago

Hello @sgozansky :wave: It looks like you didn't include the full Salesforce CLI version information in your issue. Please provide the output of version --verbose --json for the CLI you're using (sf or sfdx).

A few more things to check:

Thank you!

github-actions[bot] commented 9 months ago

Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support.

sgozansky commented 9 months ago

the full sf version { "architecture": "darwin-arm64", "cliVersion": "@salesforce/cli/2.26.10", "nodeVersion": "node-v18.17.1", "osVersion": "Darwin 23.3.0", "rootPath": "/Users/sgozansky/.nvm/versions/node/v18.17.1/lib/node_modules/@salesforce/cli", "shell": "bash", "pluginVersions": [ "@oclif/plugin-autocomplete 3.0.5 (core)", "@oclif/plugin-commands 3.1.1 (core)", "@oclif/plugin-help 6.0.12 (core)", "@oclif/plugin-not-found 3.0.9 (core)", "@oclif/plugin-plugins 4.1.21 (core)", "@oclif/plugin-search 1.0.12 (core)", "@oclif/plugin-update 4.1.8 (core)", "@oclif/plugin-version 2.0.11 (core)", "@oclif/plugin-warn-if-update-available 3.0.9 (core)", "@oclif/plugin-which 3.0.15 (core)", "@salesforce/cli 2.26.10 (core)", "apex 3.0.20 (core)", "auth 3.3.3 (core)", "data 3.0.17 (core)", "deploy-retrieve 3.2.6 (core)", "info 3.0.18 (core)", "limits 3.1.5 (core)", "marketplace 1.0.18 (core)", "org 3.3.8 (core)", "packaging 2.1.7 (link) /Users/sgozansky/.nvm/versions/node/v18.17.1/lib/node_modules/@salesforce/plugin-packaging", "schema 3.1.0 (core)", "settings 2.0.19 (core)", "sobject 1.1.3 (core)", "source 3.1.6 (core)", "telemetry 3.1.10 (core)", "templates 56.0.11 (core)", "trust 3.3.2 (core)", "user 3.2.4 (core)" ] }

github-actions[bot] commented 9 months ago

Hello @sgozansky :wave: None of the versions of sf you shared match the latest release.

Shared: 2.26.10, 2.26.10 Latest: 2.27.6

Update to the latest version of Salesforce CLI (docs) and confirm that you're still seeing your issue. You can also try the rc and nightly releases! (docs)

After updating, share the full output of sf version --verbose --json

sgozansky commented 9 months ago

I tried with { "architecture": "darwin-arm64", "cliVersion": "@salesforce/cli/2.29.0", "nodeVersion": "node-v18.17.1", "osVersion": "Darwin 23.3.0", "rootPath": "/Users/sgozansky/.nvm/versions/node/v18.17.1/lib/node_modules/@salesforce/cli", "shell": "bash", "pluginVersions": [ "@oclif/plugin-autocomplete 3.0.7 (core)", "@oclif/plugin-commands 3.1.2 (core)", "@oclif/plugin-help 6.0.12 (core)", "@oclif/plugin-not-found 3.0.10 (core)", "@oclif/plugin-plugins 4.2.1 (core)", "@oclif/plugin-search 1.0.13 (core)", "@oclif/plugin-update 4.1.10 (core)", "@oclif/plugin-version 2.0.12 (core)", "@oclif/plugin-warn-if-update-available 3.0.10 (core)", "@oclif/plugin-which 3.0.15 (core)", "@salesforce/cli 2.29.0 (core)", "apex 3.0.22 (core)", "auth 3.3.11 (core)", "data 3.0.19 (core)", "deploy-retrieve 3.2.11 (core)", "info 3.0.21 (core)", "limits 3.1.7 (core)", "marketplace 1.0.20 (core)", "org 3.3.11 (core)", "packaging 2.1.7 (link) /Users/sgozansky/.nvm/versions/node/v18.17.1/lib/node_modules/@salesforce/plugin-packaging", "schema 3.1.1 (core)", "settings 2.0.22 (core)", "sobject 1.1.9 (core)", "source 3.1.10 (core)", "telemetry 3.1.11 (core)", "templates 56.0.13 (core)", "trust 3.3.6 (core)", "user 3.2.7 (core)" ] } same issue

mshanemc commented 9 months ago

sf apex run test --tests -ycv --result-format json

--tests should specify the tests afterward (by name). And then use -y -c -v for your other flags. see sf apex run test --help for syntax and examples


what kind of package is this? Managed or unlocked?

If, as I suspect, that wasn't the real command you entered, then try a few things

  1. make sure the test you name is actually in the org. If the package is a managed package, you might need to refer to the test using its namespace.
  2. You can list classes via sf org list metadata -m ApexClass to get what the server thinks the name of the classes are
  3. you didn't include the rest of the output. Does it look like the tests you requested are running and succeeding?
sgozansky commented 9 months ago

I added a test, but I didn't write it here. I use manage package.

  1. The test is running fine - even pass.
  2. {
    "result": {
    "summary": {
      "outcome": "Passed",
      "testsRan": 2,
      "passing": 2,
      "failing": 0,
      "skipped": 0,
      "passRate": "100%",
      "failRate": "0%",
      "testStartTime": "2024-02-08T16:24:39.953Z",
      "testExecutionTime": "16634 ms",
      "testTotalTime": "16634 ms",
      "commandTime": "0 ms",
      "hostname": "<host name>",
      "orgId": "<org id>",
      "username": "<host name>",
      "testRunId": "",
      "testRunCoverage": "0%",
      "orgWideCoverage": "0%"
    },
    "tests": [
      {
        "Id": "",
        "QueueItemId": "",
        "StackTrace": "",
        "Message": "",
        "AsyncApexJobId": "",
        "MethodName": "testAB",
        "Outcome": "Pass",
        "ApexClass": {
          "Id": "01p0300000BHdlGAAT",
          "Name": "ut_ApexLimits",
          "NamespacePrefix": "FSL"
        },
        "RunTime": 2511,
        "FullName": "FSL.ut_ApexLimits.testAB"
      },
      {
        "Id": "",
        "QueueItemId": "",
        "StackTrace": "",
        "Message": "",
        "AsyncApexJobId": "",
        "MethodName": "testSchedule",
        "Outcome": "Pass",
        "ApexClass": {
          "Id": "01p0300000BHdlGAAT",
          "Name": "ut_ApexLimits",
          "NamespacePrefix": "FSL"
        },
        "RunTime": 3657,
        "FullName": "FSL.ut_ApexLimits.testSchedule"
      }
    ],
    "coverage": {
      "coverage": [],
      "records": [],
      "summary": {
        "totalLines": 0,
        "coveredLines": 0,
        "orgWideCoverage": "0%",
        "testRunCoverage": "0%"
      }
    }
    }
    }

    I can give you an org to try. and another question - in this case the two tests pass, but if one of them fails does the the run still calculate coverage?

sgozansky commented 9 months ago

I also tried to get the coverage info using this SOQL sf data query -t --query "SELECT ApexClassOrTrigger.Name, NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverageAggregate". But nothing - I am not sure it is supposed to work.

mdonnalley commented 9 months ago

@sgozansky After discussing this with a few colleagues internally, it seems that tests from managed packages don't report code coverage since orgs don't have control over the code coverage of all their installed packages.

sgozansky commented 9 months ago

Thanks for the info. @mdonnalley is this something that was supported in SFDX? I know I can do it with ant in the deployment and testing phase but it's lacking a lot of information. Is there anything you can think that will help me gather coverage information about my MP and not just 75% threshold?