forcedotcom / salesforcedx-apex

Salesforce Apex Node Library
BSD 3-Clause "New" or "Revised" License
18 stars 25 forks source link

Test results not output by default for `force:apex:test:run` #211

Closed alan-morey closed 2 years ago

alan-morey commented 3 years ago

Summary

When executing tests with force:apex:test:run the test results are not output to screen by default after command completes.

Steps To Reproduce:

MyTest.cls

@IsTest(isParallel = true)
class MyTest {
    @IsTest
    static void test1() {
        Assert.equals(1, 1 + 1);
    }

    @IsTest
    static void test2() {
        Assert.equals(2, 1 + 1);
    }

    @IsTest
    static void test3() {
        Assert.equals(3, 2 + 1);
    }
}

Given the test class MyTest exists in the Org.

$ sfdx force:apex:test:run -t MyTest

Expected result

Expected test methods of MyTest would be executed and the results written to standard output in human format, as was the behaviour in previous versions of sfdx.

Actual result

Instead of the results being written to the standard output, a message is output with instructions on how to retrieve the test results.

$ sfdx force:apex:test:run -t MyTest
Run "sfdx force:apex:test:report -i 7071F000020fQZj -u alan.morey@example.net.alandev01" to retrieve test results

Specifying -w, --wait does not change the outcome

$ sfdx force:apex:test:run -t MyTest -w 500
Run "sfdx force:apex:test:report -i 7071F000020fQgJ -u alan.morey@example.net.alandev01" to retrieve test results                                                          

Additional information

Running the same command but specifying a result format explicitly then the results get output to screen as expected:

$ sfdx force:apex:test:run -t MyTest -r human
=== Test Summary                                                                                                                                                               
NAME                 VALUE                               
───────────────────  ────────────────────────────────────
Outcome              Failed                              
Tests Ran            2                                   
Pass Rate            50%                                 
Fail Rate            50%                                 
Skip Rate            0%                                  
Test Run Id          7071F000020fRIW                     
Test Execution Time  41 ms                               
Org Id               00D1F000000YO2SUAW                  
Username             alan.morey@example.net.alandev01

=== Test Results
TEST NAME          OUTCOME  MESSAGE                                                               RUNTIME (MS)
─────────────────  ───────  ────────────────────────────────────────────────────────────────────  ────────────
MyTest.shouldFail  Fail     System.AssertException: Assertion Failed: Expected: <1>, Actual: <2>  
                            Class.Assert.fail: line 95, column 1                                  
                            Class.Assert.failNotEquals: line 145, column 1                        
                            Class.Assert.equals: line 127, column 1                               
                            Class.Assert.equals: line 108, column 1                               
                            Class.MyTest.shouldFail: line 5, column 1                                         
MyTest.shouldPass  Pass                                                                           23          

This works for formats human, tap, and json but not junit, due to another issue reported here: forcedotcom/salesforcedx-vscode#3359

SFDX CLI Version(to find the version of the CLI engine run sfdx --version):sfdx-cli/7.107.0 linux-x64 node-v14.17.1

SFDX plugin Version(to find the version of the CLI plugin run sfdx plugins --core)

$ sfdx plugins --core                                                                                                                                                                               
@alan-morey/sfdx-plugin 0.0.0 (link) /home/alan/repos/alan-morey-sfdx-plugin                                                                                                   
@oclif/plugin-autocomplete 0.3.0                                                                                                                                               
@oclif/plugin-commands 1.3.0 (core)                                                                                                                                            
@oclif/plugin-help 3.2.2 (core)                                                                                                                                                
@oclif/plugin-not-found 1.2.4 (core)                                                                                                                                           
@oclif/plugin-plugins 1.10.0 (core)                                                                                                                                            
@oclif/plugin-update 1.4.0-3 (core)                                                                                                                                            
@oclif/plugin-warn-if-update-available 1.7.0 (core)
@oclif/plugin-which 1.0.3 (core)
@salesforce/sfdx-diff 0.0.6
@salesforce/sfdx-plugin-lwc-test 0.1.7 (core)
@salesforce/sfdx-scanner 2.9.2
@salesforce/sfdx-trust 3.6.0 (core)
alias 1.1.10 (core)
apex 0.2.2 (core)
apexlink 1.3.2
auth 1.6.1 (core)
config 1.2.8 (core)
custom-metadata 1.0.12 (core)
data 0.4.12 (core)
generator 1.1.7 (core)
gr-sfdx-plugin 0.0.0 (link) /home/alan/repos/salesforce/gr-sfdx-plugin
limits 1.2.1 (core)
org 1.6.7 (core)
salesforce-alm 52.0.2 (core)                                                                                                                                                   
schema 1.0.7 (core)                                                                                                                                                            
sfdx-cli 7.107.0 (core)
telemetry 1.2.2 (core)
templates 52.0.0 (core)
user 1.3.0 (core)

OS and version: Ubuntu 18.04.5 LTS

github-actions[bot] commented 3 years 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.

AnanyaJha commented 3 years ago

Hi @alan-morey thanks for reporting this! Are you expecting the results to be outputted by default for both of the following commands?

sfdx force:apex:test:run -t MyTest & sfdx force:apex:test:run -t MyTest -w 500

alan-morey commented 3 years ago

@AnanyaJha Yes, I would have expected that the results would be output by default to screen regardless of whether the -w flag was passed or not. However, if after the wait time had lapsed and the tests were not completed, then I would expect message indicating timeout waiting and instructions on how to retrieve my test results with force:apex:test:report.

randi274 commented 2 years ago

Update on this - this will be fixed with #241, which will be available once we're out of our Dreamforce release freeze.

AnanyaJha commented 2 years ago

Hi @alan-morey this issue should be resolved with the latest version of the Apex plugin 0.3.0. Please let us know if you see otherwise!

alan-morey commented 2 years ago

Verified, results are output in human format by default.