ForceCode icon indicating copy to clipboard operation
ForceCode copied to clipboard

Code coverage is not updated when running individual tests.

Open cgb-76 opened this issue 7 years ago • 3 comments

v 3.8.6

When I run individual tests from the VS Code UI, the coverage in the corresponding APEX class is not updated. Running all tests in the test class resolves this issue.

Steps to reproduce the behavior:

  1. Create an APEX method with a conditional statement.
  2. Create two test classes, one to test each outcome.

The Controller

public with sharing class MyController {
{

    @AuraEnabled 
    public static Integer TestConditional(Boolean condition)
    {
        Integer result = 0;
        if(condition)
        {
            result = 5;
        }
        else
        {
            result = 10;
        }
        return result;
    }

}

The Test Class

@isTest(isParallel=true)
public with sharing class MyControllerTest {

    @isTest
    public static void testCondition_True() 
    {
        Test.startTest();
        Integer result = MyController.TestConditional(true);
        Test.stopTest();
        System.assertEquals(5, result);
    }

    @isTest
    public static void testCondition_False() 
    {
        Test.startTest();
        Integer result = MyController.TestConditional(false);
        Test.stopTest();
        System.assertEquals(10, result);
    }

Expected Result: When running either test in isolation, the coverage for that part of the class is updated. Actual Result: No coverage information is updated unless all tests are run.

The desired behaviour can also be achieved by running the tests individually in the SFDC developer console. When checking the 'All Tests' coverage on the tested class, coverage shows for tests that have been run, without the need to run all tests for the class.

cgb-76 avatar Sep 18 '18 23:09 cgb-76

I have verified this. There's nothing I can do about it at the moment, because it's an issue with the Salesforce cli, as I use it to run the tests in ForceCode. I did try out running tests through the Salesforce Apex extension, but that doesn't give results for running a single method or a whole class...at least not when you view the class in Salesforce. I will keep this open, but will label it with a wontfix until Salesforce resolves it in thier cli.

On another note, I was going to try and use the JSForce way of running tests, but there's no option to running single methods anymore so for now we're all SOL on this one :(

daishi4u avatar Sep 19 '18 00:09 daishi4u

I had a feeling it was going to be an issue with the CLI. It's not so bad. You can run single tests as you go to see the pass/fail data, then run all tests periodically to check for coverage. It's workable, and miles ahead of the alternative (kicking them off in dev console). Thanks for the super-fast update :)

cgb-76 avatar Sep 19 '18 01:09 cgb-76

Yeah, I tried to find a workaround ever since I saw your comment, but haven't found anything yet. You're welcome :)

daishi4u avatar Sep 19 '18 01:09 daishi4u