+ Start a Discussion
John Manager Training DepJohn Manager Training Dep 

code coverage for interface?

Hi Team,

I have the interface mentioned below,
public interface MainInterface {
 
  void bInsert();
  void bUpdate();
  void bDelete();
  void aInsert();
  void aUpdate();
  void aDelete();
  void aUndelete();
 
}
I want to get overall code coverage of 100% for the interface, Any suggestions please?
MKRMKR
Hi,

Interfaces cannot have code coverage. Interfaces have in practice 0 lines that could be covered and thus they remain at 0% coverage. That does not have any impact on the 75% rule. Just make sure that you test the implementing classes properly and you should be good to go.

Regards,
MKR
Khan AnasKhan Anas (Salesforce Developers) 
Hi John,

Greetings to you!

The interface doesn't need to be tested but any class that implements the interface will need test coverage. 
public interface MainInterface {
   void bInsert();
}

Above interface does not need to be test covered but the implementations do need coverage.
public class SomeClass implements MainInterface {
  public void bInsert() {
    // lines of code implementing bInsert() method must be covered
 }
}

Please refer to the below link which might help you further.

https://sfdcknowledgebank.wordpress.com/2013/09/30/code-coverage-for-interface/

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Ajay K DubediAjay K Dubedi
Hi John,

The interface doesn't need to be tested but any class that implements the interface will need test coverage. So,
public interface MainInterface {
 
  void bInsert();
  void bUpdate();
  void bDelete();
  void aInsert();
  void aUpdate();
  void aDelete();
  void aUndelete();
 
}

does not need to be test covered but the implementations of the above interface need coverage.

For detail, please go to the below link:
https://developer.salesforce.com/forums/?id=906F000000092cdIAA
https://salesforce.stackexchange.com/questions/51757/how-to-achieve-test-coverage-for-interface-classes

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too. 

Thanks,
Ajay Dubedi
www.ajaydubedi.com
John Manager Training DepJohn Manager Training Dep
Hi Team,
Thanks for the wonderful responses. I created a class that implements the interface.
public class MainInterfaceImplements implements MainInterface{
    	public void bt(){system.debug('');}
		public void bUpdate(){system.debug('');}
		public void bDelete(){system.debug('');}
		public void aInsert(){system.debug('');}
		public void aUpdate(){system.debug('');}
		public void aDelete(){system.debug('');}
		public void aUndelete(){system.debug('');}
}

I created Test Class for above,
@isTest
public class MainInterfaceTest{
    
    static testMethod void mainInterfaceTestFunc(){
        MainInterfaceImplements inst = new MainInterfaceImplements ();
        inst.bInsert();
        inst.bUpdate();
        inst.bDelete();
        inst.aInsert();
        inst.aUpdate();
        inst.aDelete();
        inst.aUndelete();
        
    }

}

Even though the test class covered 100% for MainInterfaceImplements , I still see the code coverage for interface as 0%. If I understand, its correct and would not impact moving the code to next stage. Please correct me.

Please let me know if could find documentation on this.