나는 Apex에 노동 계급을 썼다. 수신 전자 메일을 처리하는 전자 메일 서비스 Extender입니다. 내 샌드 박스 환경에서 완벽하게 작동합니다.apex force.com 코드의 테스트 클래스에 어떤 문제가 있습니까?
테스트 클래스를 만들었으므로 프로덕션 환경에도 배포 할 수 있지만 코드 유효성을 검사 할 때 코드의 72 % 만 테스트됩니다.
이 내 메인 클래스
global class inboundEmail implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
Lead lead;
String [] mFromUserParams;
String [] sourceText;
String mCaseObject;
try{
sourceText = email.toAddresses[0].split('@');
String [] mParams = sourceText[0].split('\\.');
**// FROM THIS LINE TO THE END - NOT COVERED**
mFromUserParams = email.fromAddress.split('@');
mCaseObject = mParams[0];
if (mCaseObject == 'lead'){
lead = new Lead();
lead.LastName = mFromUserParams[0];
lead.Company = email.fromAddress;
lead.OwnerId = mParams[1];
lead.LeadSource = mParams[2];
lead.Email = email.fromAddress;
lead.RequirementsDescription__c = email.subject + email.plainTextBody;
insert lead;
result.success = true;
} else if (mCaseObject == 'case'){
result.success = true;
} else {
result.success = false;
}
}catch(Exception e){
result.success = false;
result.message = 'Oops, I failed.';
}
return result;
}
}
이 오류 메시지에 따라 내 테스트 클래스
@isTest
private class inboundEmailTest {
public static testMethod void inboundEmail(){
// Create a new email, envelope object and Header
Messaging.InboundEmail email = new Messaging.InboundEmail();
Messaging.InboundEnvelope envelope = new Messaging.InboundEnvelope();
envelope.toAddress = 'lead[email protected]';
envelope.fromAddress = '[email protected]';
email.subject = 'Please contact me';
email.fromName = 'Test From Name';
email.plainTextBody = 'Hello, this a test email body. for testing Bye';
// setup controller object
inboundEmail catcher = new inboundEmail();
Messaging.InboundEmailResult result = catcher.handleInboundEmail(email, envelope);
}
}
이다, 3 번째 줄에서 try/catch 블록의 모든 라인은 포함되지 않습니다. (코드에 표시).
음, 나도 그렇게 생각했지만 봉투에는 toAddresses [] 객체가 필요하지 않습니다. 오직 하나의 문자열 개체로. – Saariko
엔벨로프 개체가 필요하지 않습니다. 단지'email.toAddresses = new List { '[email protected]'}; '을 설정하십시오. –
h9nry
나는 inboundEmail InboundEmail은 내부 개체입니다. 어쩌면 그것이 간섭했는지 모릅니다. email.fromAddress에서 LIST를 제거하면이 문제가 해결됩니다. 감사 – Saariko