You need to sign in to do that
Don't have an account?
Javier Maldonado
Test Code - No errors but not code coverage
Hello everyone,
Can somebody give me a hand... I just createD this test code, but it is not giving me any code coverage, and no errors neither...
TRIGGER
trigger SelectRecordType on Case (before insert) {
for (case cs :Trigger.new){
if(cs.Type == 'Billing Adjustment'){
cs.RecordTypeId='012180000004KrD';
}
else if(cs.Type == 'RMA'){
cs.RecordTypeId='01240000000IbO4';
}
}
}
TEST
@isTest(seeAllData=True)
public class SelectRecordType_Test {
static TestMethod void SelectRecordType(){
case c = new case();
string tp = c.Type;
if(tp == 'Billing Adjustment'){
c.RecordTypeId='012180000004KrD';
} else if(tp == 'RMA'){
c.RecordTypeId='01240000000IbO4';
}
}
}
Can somebody give me a hand... I just createD this test code, but it is not giving me any code coverage, and no errors neither...
TRIGGER
trigger SelectRecordType on Case (before insert) {
for (case cs :Trigger.new){
if(cs.Type == 'Billing Adjustment'){
cs.RecordTypeId='012180000004KrD';
}
else if(cs.Type == 'RMA'){
cs.RecordTypeId='01240000000IbO4';
}
}
}
TEST
@isTest(seeAllData=True)
public class SelectRecordType_Test {
static TestMethod void SelectRecordType(){
case c = new case();
string tp = c.Type;
if(tp == 'Billing Adjustment'){
c.RecordTypeId='012180000004KrD';
} else if(tp == 'RMA'){
c.RecordTypeId='01240000000IbO4';
}
}
}
Try with below code it will help !
Thanks
Manoj
All Answers
Thanks,
Kaustav
1 - Never never never never use "seeAllData=true" unless you ABSOLUTELY have to (there are some instances where you need to do it, but this isn't one of them).
2- Your unit test is designed to run the targeted (trigger) code, so you have to do a DML insert in your test class to invoke it. You will end up creating two individual cases (each with the RecordType in question) and insert both.
Another note - you also want to avoid specific record/recordtype Ids in your code (regular and unit test) - you can query the RecordType object on the Name/DeveloperName to get the id back. If you leave the Id in the code - you run the risk of this not working when you promote the code to Production.
Sample Trigger
Test Class
Thanks,
Kaustav
Try with below code it will help !
Thanks
Manoj