You need to sign in to do that
Don't have an account?
karthik Jonnalagadda
Code Coverage Issue for trigger
Hello all,
I write a test case for trigger, I got code coverage 72% but while pushing into production it showing code coverage is 0% need at least 1 %.
what was the issue please any solutions
I write a test case for trigger, I got code coverage 72% but while pushing into production it showing code coverage is 0% need at least 1 %.
what was the issue please any solutions
@isTest public class TestSetIsCopiedToProjectFlagFalse { static testmethod void TestTriggerIsCopiedToProjectFlag() { Ibanking_Project__c Obj = new Ibanking_Project__c(); obj.Id='a0Bj00000031Gu6'; delete obj; } }
Don't hard code Id .Create a record by adding mandatory field and insert and then delete .
Ibanking_Project__c obj = new Ibanking_Project__c();
obj.Name='test name ';
insert obj ;
LIke above you need to mandatory fields .
As id will not match in production org so it will not cover your code .
Let me know if it helps .
Thanks
Manoj
As a best practise we should not hardcode the id in test class...because when you will deploy your code to production that time this id will not be there ...
Simply you can insert , update and delete records in test class as per your need ...
So if your trigger is on delete if this object then you can first insert the record and then you can delete it..like
Ibanking_Project__c objIbanking_Project__c = new Ibanking_Project__c (Name='Test');//provide all mandatory field..
Insert objIbanking_Project__c ;
Delete objIbanking_Project__c ;
Thanks,
Sandeep
now i changed the code bellow
Now I got the error : System.QueryException: List has no rows for assignment to SObject
Class.TestSetIsCopiedToProjectFlagFalse.TestTriggerIsCopiedToProjectFlag: line 5, column 1
can you please help me out
Thanks.
Try with below code .
Els eyou need to add @isTest(SeeAllData=true ) still it is not good practice .
Thanks
Manoj
instead of query wqe can insert the account record also and then we can use the id lik ebelow...
please privide all mandatory fields and insert the account as I showed above , that will work for you..
Thanks,
sandeep
I used your code now got this error.
Methods defined as TestMethod do not support Web service callouts, test skipped
Check if anywhere a future callout has been made.
Check the below link on fixing such issue
http://salesforce.stackexchange.com/questions/3486/testing-httpcallout-with-httpcalloutmock-and-unittest-created-data/5070#5070.
Sailaja