function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
StarhunterStarhunter 

Test class coverage using asserts.

Below is a class where three string constants are declared. 
public with sharing class testconstants{
public static string str1 ='firststring';
public string str2='secondstring';
public string str3='thirdstring';
}
I wrote a test class for this:
@isTest
public class testcontants_testclass{
static testmethod void method1()
{
testconstants t = new testconstants();
test.starttest();
system.assertEquals(testconstants.str1,'firststring');
test.stoptest();
}
}
Now the coverage for this class should only be 33% but the coverage is touching 100%.  So it remains 100% even if i keep one assert or two asserts for the three strings.
KKNKKN
Hi,

As soon as an instance is created for the apex class (controller), all the variables declared in the class gets covered. No need to specifically call the variable to get coverage.
Assert statements are not used to cover the code. It is used to check whether we are getting the corrects results or not.