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
Baz DensonBaz Denson 

Send data to a constructor from test class

I have the bare bones of a test class
 
@isTest
public class sendEmailInvocableTest {

    static testMethod void testUseCase1() {
        List<sendEmailInvocable.emailParam> Params = new List<sendEmailInvocable.emailParam>();

        
    	sendEmailInvocable.SendEmail(Params);
    }

Which works, but I am having trouble with sending data to the constructor. This is my constructor
 
public class emailParam{
		@InvocableVariable(required=true)       public String sendTo;
		@InvocableVariable        				public String ccTo;
		@InvocableVariable       				public String salutation;
		@InvocableVariable(required=true)       public String replyTo;
		@InvocableVariable(required=true)       public String senderDisplayName;
		@InvocableVariable(required=true)       public String subject;
		@InvocableVariable(required=true)       public String plainBody;
		@InvocableVariable(required=true)       public String HTMLBody;
		@InvocableVariable        				public String customVar1;
		@InvocableVariable        				public String customVar2;
		@InvocableVariable        				public String customVar3;
		@InvocableVariable        				public String customVar4;
		@InvocableVariable        				public String customVar5;

    }

How do I pass data to the constructor?

Thanks

Barry
Best Answer chosen by Baz Denson
Baz DensonBaz Denson
I think I have solved it. I have done
 
@isTest
public class sendEmailInvocableTest {

    static testMethod void testUseCase1() {
        List<sendEmailInvocable.emailParam> Params = new List<sendEmailInvocable.emailParam>();

		sendEmailInvocable.emailParam p = new sendEmailInvocable.emailParam();
        p.sendTo = 'barry.denson@hotmail.com';
		p.ccTo = 'barry.denson@hotmail.com';
		p.salutation = 'Barry';
		p.replyTo = 'barry.denson@hotmail.com';
		p.senderDisplayName = 'Barry Denson';
		p.subject = 'Test Class';
		p.plainBody = 'Plain Body';
		p.HTMLBody = 'HTML Body';
		p.customVar1 = 'Custom Var 1';
		p.customVar2 = 'Custom Var 1';
		p.customVar3 = 'Custom Var 1';
		p.customVar4 = 'Custom Var 1';
		p.customVar5 = 'Custom Var 1';		
        Params.add(p);
        
    	sendEmailInvocable.SendEmail(Params);
    }
          

}

Which works and gives 100% code coverage. I realise I need to do some asserts etc, but as far as the code goes, have I done it right and is there a better way to do it?