Skip to main content
edited tags
Link
Chris Duncombe
  • 24.3k
  • 13
  • 77
  • 116
added 20 characters in body
Source Link
Mohith Shrivastava
  • 91.9k
  • 19
  • 161
  • 214
@isTest

public class UnitTests_CreateNewTask10 {

static testMethod void CreateNewTask10() {

 public class UnitTests_CreateNewTask10 {

  static testMethod void CreateNewTask10() {

  //Set up user
  User u1 = [SELECT Id FROM User WHERE Alias='auser'];

  test.startTest();
  
  //Run As U1
  System.RunAs(u1){
  
  Lead l = new Lead(
       FirstName='Test firstName',
       LastName = 'Test LastName', 
       Comments__c = '18888 test comments'
       );

  insert l;
  System.debug('Created and inserted lead');

  List<Task> tasks = new List<Task>();
  
  tasks.add(new Task(
     ActivityDate = Date.today().addDays(7),
     WhoId = l.Id,
     Status = 'Not Started',
     type='Other',
     Priority='Normal',
     Subject='trigger add New Comment',
     Description = l.Comments__c
  ));
     
  insert tasks;
  System.debug('Created and inserted task');

  Task Ttest = [SELECT Whoid, Description FROM Task WHERE Whoid=:l.Id Limit 1];

  system.assertEquals('18888 test comments', Ttest.Description);
 
  test.stopTest();
  
    } //end RunAs(u1) 

  }

 }

}

}

@isTest

public class UnitTests_CreateNewTask10 {

static testMethod void CreateNewTask10() {

  //Set up user
  User u1 = [SELECT Id FROM User WHERE Alias='auser'];

  test.startTest();
  
  //Run As U1
  System.RunAs(u1){
  
  Lead l = new Lead(
       FirstName='Test firstName',
       LastName = 'Test LastName', 
       Comments__c = '18888 test comments'
       );

  insert l;
  System.debug('Created and inserted lead');

  List<Task> tasks = new List<Task>();
  
  tasks.add(new Task(
     ActivityDate = Date.today().addDays(7),
     WhoId = l.Id,
     Status = 'Not Started',
     type='Other',
     Priority='Normal',
     Subject='trigger add New Comment',
     Description = l.Comments__c
  ));
     
  insert tasks;
  System.debug('Created and inserted task');

  Task Ttest = [SELECT Whoid, Description FROM Task WHERE Whoid=:l.Id Limit 1];

  system.assertEquals('18888 test comments', Ttest.Description);
 
  test.stopTest();
  
  } //end RunAs(u1)

}

}

@isTest
 public class UnitTests_CreateNewTask10 {

  static testMethod void CreateNewTask10() {

  //Set up user
  User u1 = [SELECT Id FROM User WHERE Alias='auser'];

  test.startTest();
  
  //Run As U1
  System.RunAs(u1){
  
  Lead l = new Lead(
       FirstName='Test firstName',
       LastName = 'Test LastName', 
       Comments__c = '18888 test comments'
       );

  insert l;
  System.debug('Created and inserted lead');

  List<Task> tasks = new List<Task>();
  
  tasks.add(new Task(
     ActivityDate = Date.today().addDays(7),
     WhoId = l.Id,
     Status = 'Not Started',
     type='Other',
     Priority='Normal',
     Subject='trigger add New Comment',
     Description = l.Comments__c
  ));
     
  insert tasks;
  System.debug('Created and inserted task');

  Task Ttest = [SELECT Whoid, Description FROM Task WHERE Whoid=:l.Id Limit 1];

  system.assertEquals('18888 test comments', Ttest.Description);
 
  test.stopTest();
  
    } //end RunAs(u1) 

  }

 }
Source Link
webon100
  • 61
  • 1
  • 7

deploy run test pass, but still display Test coverage of selected Apex Trigger is 0%, at least 1%

deploy issue: run test pass, but when i deploy to production, it still display Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required, can anyone tell me what i miss here ?

Apex Trigger: failed to deploy: message: "Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required"

trigger CreateNewTask10 on Lead (after insert) {

List<Task> lNewTasks = new List<Task>();
for (Integer i = 0; i < Trigger.new.size(); i++) {

         if (Trigger.new[i].Comments__c !=null) {
            lNewTasks.add(new Task(
                ActivityDate = Date.today().addDays(7),
                WhoID=Trigger.new[i].Id,
                Status = 'Not Started',
                type='Other',
                Priority='Normal',
                Subject='trigger add New Comment',
                description = Trigger.new[i].Comments__c
                ));
         }
        }

insert lNewTasks;

Apex class - test and pass

@isTest

public class UnitTests_CreateNewTask10 {

static testMethod void CreateNewTask10() {

  //Set up user
  User u1 = [SELECT Id FROM User WHERE Alias='auser'];

  test.startTest();
  
  //Run As U1
  System.RunAs(u1){
  
  Lead l = new Lead(
       FirstName='Test firstName',
       LastName = 'Test LastName', 
       Comments__c = '18888 test comments'
       );

  insert l;
  System.debug('Created and inserted lead');

  List<Task> tasks = new List<Task>();
  
  tasks.add(new Task(
     ActivityDate = Date.today().addDays(7),
     WhoId = l.Id,
     Status = 'Not Started',
     type='Other',
     Priority='Normal',
     Subject='trigger add New Comment',
     Description = l.Comments__c
  ));
     
  insert tasks;
  System.debug('Created and inserted task');

  Task Ttest = [SELECT Whoid, Description FROM Task WHERE Whoid=:l.Id Limit 1];

  system.assertEquals('18888 test comments', Ttest.Description);
 
  test.stopTest();
  
  } //end RunAs(u1)

}

}