• Mischa14
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

 

Hi All,

I am new to apex triggers, but somehow I managed to create a trigger that works.. I am having more trouble creating a Test Class that reaches 75% of code coverage.. my Test Class sticks at 0% coverage :-(

my trigger fires after the creation of a custom object, called Case.. the trigger inserts a Case Leadtime record in the related list on Case (the case leadtime record is then filled with workflow rules to track the leadtime per department for management reporting ).

This is the trigger:

 

trigger createLeadtime on Case__c (after insert)
{

List<Case_Leadtime__c> cl = new List<Case_Leadtime__c>();
for (Case__c newCase_Leadtime: Trigger.New)
cl.add (new Case_Leadtime__c(
Case__c = newCase_Leadtime.Id));
insert cl;
}

 

 

In the Test Class I have intended to first create a Case and then to create a related Case Leadtime

 

This is the test class:


@isTest
private class TestcreateLeadtime {

static testMethod void TestcaseLeadtime () {

Case__c a = new Case__c ();
a.Account__c = [select Id from Account limit 1].Id;
a.Issue_Type__c = 'Customer Claim';
a.Office__c = [select Id from Office__c limit 1].Id;
a.Case_Created_By__c = 'Test';
a.Assigned_To__c = [select Id from User limit 1].Id;
a.Status__c = 'Open';
a.Complaint_Subject__c = 'Miscellaneous';
a.Change_Flag__c = true;
a.Proposed_Solution__c = 'Discount/Compensate By Credit Note';
insert a;

Case_Leadtime__c[] cl = new Case_Leadtime__c []{
new Case_Leadtime__c (Case__c = a.id)};
insert cl;


test.startTest();
insert cl;
test.stopTest();
}

}

 

------

 

Hope someone can help

 

Thanks

 

 

Hi All,

I am new to apex triggers, but somehow I managed to create a trigger that works.. I am having more trouble creating a Test Class that reaches 75% of code coverage.. my Test Class sticks at 0% coverage :-(

my trigger fires after the creation of a custom object, called Case.. the trigger inserts a Case Leadtime record in the related list on Case (the case leadtime record is then filled with workflow rules to track the leadtime per department for management reporting ).

This is the trigger:

 

trigger createLeadtime on Case__c (after insert)
{

List<Case_Leadtime__c> cl = new List<Case_Leadtime__c>();
for (Case__c newCase_Leadtime: Trigger.New)
cl.add (new Case_Leadtime__c(
Case__c = newCase_Leadtime.Id));
insert cl;
}

 

 

In the Test Class I have intended to first create a Case and then to create a related Case Leadtime

 

This is the test class:


@isTest
private class TestcreateLeadtime {

static testMethod void TestcaseLeadtime () {

Case__c a = new Case__c ();
a.Account__c = [select Id from Account limit 1].Id;
a.Issue_Type__c = 'Customer Claim';
a.Office__c = [select Id from Office__c limit 1].Id;
a.Case_Created_By__c = 'Test';
a.Assigned_To__c = [select Id from User limit 1].Id;
a.Status__c = 'Open';
a.Complaint_Subject__c = 'Miscellaneous';
a.Change_Flag__c = true;
a.Proposed_Solution__c = 'Discount/Compensate By Credit Note';
insert a;

Case_Leadtime__c[] cl = new Case_Leadtime__c []{
new Case_Leadtime__c (Case__c = a.id)};
insert cl;


test.startTest();
insert cl;
test.stopTest();
}

}

 

------

 

Hope someone can help

 

Thanks