4

I am using the trigger framework presented here, which uses several interfaces and utility classes:

http://krishhari.wordpress.com/2013/07/22/an-architecture-framework-to-handle-triggers-in-the-force-com-platform/

And my question is the following: How does one achieve test coverage for Interfaces? Are these even factored in to test coverage?

3

The interface doesn't need to be tested but any class that implements the interface will need test coverage

So ..

public interface IFoo {
   void doBar();
}

does not need to be test covered but the implementations do need coverage

public class MyClass implements IFoo {
  public void doBar() {
    // lines of code implementing doBar() method must be covered
 }
}

The trigger framework you mentioned requires you to provide implementations of the various trigger handlers. When you do DML in your testmethods, the triggers will execute and the handlers will then get coverage

  • I had a misunderstanding about the calculation, which had not been performed because I was only running tests in the test runner interface. Now I seem to have code coverage numbers that are in line with what I expected. – atmdd Oct 8 '14 at 19:35
  • Actually, that's not true. For example, I have implemented the virtual methods for afterInsert and afterUpdate, and I am using an upsert DML operation to perform an upsert, and yet it says they are not covered. Am I missing something else here? – atmdd Oct 8 '14 at 19:51
  • upsert will do an insert if there is no value for the id field, an update if there is a value for the id field. hence, different handlers (before/after insert vs before/after update) will be invoked. Did you cover both use cases in your testmethod? – cropredy Oct 8 '14 at 21:00
  • I have only covered the insert case technically, so it makes sense why the update one wouldn't be covered. Shouldn't the insert one at least be covered though? I am going to refactor my test code so that I can more easily test the update case. I'll leave your answer as accepted for now unless I can show a concrete example of it not working after the refactor. – atmdd Oct 8 '14 at 21:43
  • Alright, I have a unit tests that exercises a TriggerDispatcher afterInsert method. However, the TriggerDispatcherBase class has a virtual method afterInsert, and dev console is saying that the method is not covered by a test. So it would appear that testing it is impossible. – atmdd Oct 10 '14 at 15:48

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.