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
Unisoft PhucVVUnisoft PhucVV 

Different result test IDE and Developer Console

/**
 * Function attach file to email
 */
public PageReference attachFileToEmail() {

    // In case have file 
    if(attachment.Name != null) {
        // Get parentID
        EmailTemplate parentTemplate = [SELECT Id FROM EmailTemplate LIMIT 1];

        // Set ParentId and Description
        attachment.ParentId = parentTemplate.Id;
        try {
            // Insert file
            insert attachment;

            // Clear body file
            attachment.Body = null;

            if(attachment.Id != null) {
                uploadedAttachments.add(attachment);
            }
        } catch (DMLException e) {
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,UPDATE_FILE_FAILD_ERROR_MESSAGE));
        } finally {
            attachment = new Attachment(); 
        } 
    } else {
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,NO_CHOSE_FILE_ERROR_MESSAGE));
    } 

    return null;

}
My function:

My unit test:
/**
 * attachFileToEmail test
 * Insert success
 */
@isTest
static void AttachFileToEmailSuccessTestCase1() {
    // Create data
    Task[] results;
    BulkEmailSenderControllerTest mgr = new BulkEmailSenderControllerTest();
    BulkEmailSenderController controller = new BulkEmailSenderController();
    mgr.createEmailTemplateData();

    // Create data
    controller.attachment.Name='Unit Test Attachment';
    Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body');
    controller.attachment.body = bodyBlob;
    controller.attachment.parentId = [SELECT Id FROM EmailTemplate LIMIT 1].Id;

    // Running test
    Test.startTest();

    controller.attachFileToEmail();

    Test.stopTest();

    // Compare
    System.assertEquals(1, controller.uploadedAttachments.size());
}

When I run test in Eclipse, this unit test is pass . However on Developer Console Tool is failed with message (System.AssertException: Assertion Failed: Expected: 1, Actual: 0).

Please help my problem.
sandeep sankhlasandeep sankhla
Hi,

Make sure you ahev latestcode in your eclipse, simply take referesh from server and then chck the test coverage from eclipse and let me know if you still face the same error..

Thanks,
Sandeep
Amit Chaudhary 8Amit Chaudhary 8
Try Run Run Test from salesforce UI then refresh your IDE code and then try from all three place. It will work.
Please let us know if this will help you