0

I have a Trigger Framework Handler Test Class that extends the TriggerHandler. In the override method, I am only simply calling a method from a different class. How can I do unit test here? Following is the sample code. Thanks.

@isTest
public with sharing class MyTriggerHandler_Test extends TriggerHandler {
    @isTest
    public override void afterInsert(){
        MyAnotherClass.methodInMyAnotherClass();
    }
}
1
  • 1
    Why will a test class extend TriggerHandler? Dec 29 '20 at 5:15
0

I am not sure why a test class extends TriggerHandler.

You can simply just write a Test Class, and call the handler method from your test class.

For eg:

Lets say you have a trigger handler class as below:

public class UserNoticeManagementTriggerHandler extends TriggerHandler {

In your test class you can simply do either this:

@isTest
private static void testAfterInsert(){
    UserNoticeManagementTriggerHandler.yourmethodname();
}

Or just insert data, the trigger handler will run and cover your required lines.

4
  • Right. Thanks. That's all is needed. But what about assert statements? At least one is required, right? as per PMD best practices.
    – user91213
    Dec 29 '20 at 5:34
  • 1
    how will you test abstract class or interface? by extending them in testclass. The idea is to test the abstraction and not the actual implementation. Dec 29 '20 at 5:37
  • @STSF If the statement does any DML or return any value, you can assert the return value or the DB value. Dec 29 '20 at 5:38
  • No, this has just one line of code to call another method.
    – user91213
    Dec 29 '20 at 6:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy