You need to sign in to do that
Don't have an account?
Chinmay Abhangrao
Why my test class fail when i user System.AssertEquals() method in it?
I have written this test class but it fails all the time and when I commit the system.assert();statement then it works fine.Anybody can explain where I am lagging?
@istest public class TestingExam {
@istest public static void Testing(){
Account ac=new account();
ac.Name='chinamyab';
insert ac;
case c=new case();
c.AccountId=ac.Id;
c.Status='working';
c.Origin='phone';
c.Product__c='GC1040';
insert c;
System.assertEquals(1,ac.Total_Issue_Count__c);
System.assertEquals('GC1040',ac.Current_Issue__c);
}
}
@istest public class TestingExam {
@istest public static void Testing(){
Account ac=new account();
ac.Name='chinamyab';
insert ac;
case c=new case();
c.AccountId=ac.Id;
c.Status='working';
c.Origin='phone';
c.Product__c='GC1040';
insert c;
System.assertEquals(1,ac.Total_Issue_Count__c);
System.assertEquals('GC1040',ac.Current_Issue__c);
}
}
According to your code here, your are refering Two fields of Account (1. Total_Issue_Count__c, 2. Current_Issue__c) in Assert method which might be getting updated by your Workflow/trigger while inserting Case record.
And that functionality is not working properly, check with that. Or provide your Workflow/trigger details here.
Let me know if not found solution.
Thanks
Niraj
trigger ProdTrackOnAcc on Case (after insert,after update,after delete)
{
//TriggerOnCase__c newObj= TriggerOnCase__c.getInstance();
//if( newObj.IsActive__c==true)
//{
If(Trigger.isinsert && Trigger.isafter)
{
set<id> setid=new set<id>();
for(Case c:trigger.new )
{
setid.add(c.AccountId);
}
list<account> acctoup=new list<account>();
map<id,Account> acclist=new map<id,Account>([select id,Current_Issue__c,Past_Issue__c,Total_Issue_Count__c from account where id=:setid]);
for(Case c:trigger.new)
{
account a=acclist.get(c.AccountId);
If(a.Total_Issue_Count__c==NULL)
{
a.Total_Issue_Count__c=0;
}
a.Total_Issue_Count__c= a.Total_Issue_Count__c+1;
if(a.Current_Issue__c==null)
{
a.Current_Issue__c= c.Product__c;
}else if(a.Current_Issue__c!=null)
{
String toSet;
toset= ','+c.Product__c;
String acur= a.Current_Issue__c;
a.Current_Issue__c= acur+(toset);
System.debug('current issue is'+ a.Current_Issue__c);
}
acctoup.add(a);
// EmailSendToOwner obj=new EmailSendToOwner();
// String ownermailid=a.owner.email;
// String EmailIdOfOwner =acclist.get(c.AccountId).Owner.Email;
// obj.sendMail(EmailIdOfOwner, 'subject', 'body');
//System.debug(EmailIdOfOwner);
}
update acctoup;
}
System.AssertException: Assertion Failed: Expected: 1, Actual: null
Try the below code:
IF you found this answer helpful then please mark it as best answer so it can help others.
Thanks
Akshay
I have written trigger for that when a case raises then automatically the total issue count increases by 1.
Now you need to update your test class and use this: