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
W Chad SmithW Chad Smith 

Test Coverage for a Class of Constants

I have a class that is this:

 

public with sharing class Constants {
    public static final String NOZZLE = 'Nozzle'; 
    public static final String MANIFOLD = 'Manifold';
    public static final String INLET = 'Inlet';

 

 

I am attempting to write test code for it, test class looks like this:

 

@isTest
private class Test_Constants {

    static testMethod void myUnitTest() {
		Constants con = new Constants();
		System.assertEquals(Constants.ACTUATOR_COST,Constants.ACTUATOR_COST);

 For some reason I'm getting 0 test coverage.  For the Systerm.assert, I tried con. rather than constants. but got an error... Added in a System.Debug in the test as well and the string value for the variable is getting pulled, not sure why Salesforce is reporting 0 coverage.

Best Answer chosen by Admin (Salesforce Developers) 
W Chad SmithW Chad Smith

Thanks everyone... Yeah after reading these and more experimenting, it seems as those variable declarations can't really be tested, but at the same time aren't counted in test coverage, so it's 0 of 0.

 

 

All Answers

Eli Flores, SFDC DevEli Flores, SFDC Dev
there's no code to cover. Try adding a blank constructor.

public void Constants(){}

You may need at least 1 line of running code though to get coverage.
davidjgriffdavidjgriff
DevArrah beat me to it. The only way I was able to get any coverage on a class like that is to add an empty method that does nothing and run that from the test method. The constants never get any coverage, but it covers the only "action" within the class, so Salesforce gives it 100% coverage.
W Chad SmithW Chad Smith

Thanks everyone... Yeah after reading these and more experimenting, it seems as those variable declarations can't really be tested, but at the same time aren't counted in test coverage, so it's 0 of 0.

 

 

This was selected as the best answer