Skip to content

Code coverage is not updated when running individual tests. #94

@cgb-76

Description

@cgb-76

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions