Test class for Email Services classes in Salesforce

In the test class, follow the below

1. Create Messaging.InboundEmail.

2. Create Messaging.InboundEnvelope.

3. Pass them to handleInboundEmail() method of Messaging.InboundEmailHandler class.

Sample Test Class Code:

Messaging.InboundEmail email = new Messaging.InboundEmail() ;
Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();

email.subject = 'Test';
email.fromname = 'Test Test';
env.fromAddress = '[email protected]';
email.plainTextBody = 'Test';

CreateLeadInboundHandler emailProcess = new CreateLeadInboundHandler();
emailProcess.handleInboundEmail(email, env);

here CreateLeadInboundHandler is a Email Service controller class.