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
MaheemSamMaheemSam 

Code Coverage for blank class

Hi, 

  I have a class below which has no code I want to get coverage for below class
public class PP_HandleException extends Exception {
  
}
Wrote test class as mentioned blelow. Still showing 0% as code coverage 
@isTest(seealldata=false)
public class PP_HandleExceptionTest{
    static testMethod void PP_HandleException(){
        Test.startTest();
       PP_HandleException PP = new PP_HandleException('test');
    
        Test.stopTest();
    }  
}

  Please suggest me how to get code coverage.

Thanks
Sudhir
 
Newbie__SalesforceNewbie__Salesforce
Hi MaheemSam, 

You are not calling the method name.

Update ur Class as following - 
public class PP_HandleException extends Exception {
  public void methodName() {
     
   }
}

Update ur test class - 
@isTest(seealldata=false)
public class PP_HandleExceptionTest{
    static testMethod void PP_HandleException(){
        Test.startTest();
       PP_HandleException PP = new PP_HandleException('test');
       PP.methodName(); 
        Test.stopTest();
    }  
}

 
MariuszMariusz
You can also try with new constructor
public class PP_HandleException extends Exception {
    public PP_HandleException(String message, String dummyMessage) {}
}
and test class
@isTest
public class PP_HandleExceptionTest {
	static testMethod void PP_HandleException(){
        Test.startTest();
        PP_HandleException he = new PP_HandleException('test', 'message');
        Test.stopTest();
    } 
}
Ajay K DubediAjay K Dubedi
Hi MaheemSam,

Please try the code below for 100% code coverage:

public class PP_HandleException extends Exception {
 public static void exceptionmethod()
 {
     
 }
}

Test class:

@istest
public class HandleCodeTest {
    
static testMethod void PP_HandleException(){
        Test.startTest();
       PP_HandleException.exceptionmethod();
    
        Test.stopTest();
    }  
}

The reason you were not able to find code coverage in your code was that of the absence of method
or constructor in your class. Writing a test class for a class without having a method or constructor would be meaningless.
I hope you will find this explanation helpful. Please mark it as best answer if you find it helpful.

Thanks.
Ajay Dubedi