0

Heres my apex class(from the doc)

public class TVRemoteControl {

    Integer volume;
    static final Integer MAX_VOLUME = 50;

    public TVRemoteControl(Integer v)
    {
        volume = v;
    }

    public Integer increaseVolume(Integer amount)
    {
        volume += amount;
        if(volume > MAX_VOLUME) 
            volume = MAX_VOLUME;
        return volume;

    }

    public Integer decreaseVolume(Integer amount)
    {
        volume -= amount;
        if(volume < 0) 
            volume = 0;
        return volume;
    }

    public static String getMenuOptions(String s)
    {
        return s.reverse();
    }
}

Heres my test class for the above class

@isTest
class TVRemoteControlTest {

    @isTest static void testVolumeIncrease()
    {
        TVRemoteControl t = new TVRemoteControl(10);
        t.increaseVolume(100);
    }

    @isTest static void testgetMenuOptions()
    {
        //TVRemoteControl.getMenuOptions();
        System.assertEquals('Alpha',TVRemoteControl.getMenuOptions('Alpha').reverse() );
    }

    @isTest static void testdecreaseVolume()
    {
        TVRemoteControl t = new TVRemoteControl(5);
        t.decreaseVolume(-100); //Line X
    }

}

The TVRemoteControl class had 100% code coverage via the test class TVRemoteControlTest class.

I made some change in the test class (see Line X)..Changed the sign of the input from + to -.

As soon as I did that I noticed that the code coverage of TVRemoteControl went down to 0%.

Do note that I have not ran the test by that point only made changes in the TVRemoteControlTest test class.

My question is how a change in a test class reduce the code coverage to 0% when I did not even run the test but only made changes on the testing class ?.

Hope I am clear.

2

I think this is feature of SFDC. When you update Test class then SFDC does not know what is new code coverage until we rerun the test class. To show this unknown number it just reset the old coverage to 0%. When you will re run the test it will show the exact percentage of coverage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.