You need to sign in to do that
Don't have an account?
santhosh konathala 17
Hi I am new to Test classes can anybody suggest how to write a Test class for the below Trigger?
trigger Deleteres on Restintegration__c(after update) {
List<Id> lstId = new List<Id>();
if(trigger.isupdate)
{
for(Restintegration__c res : trigger.new)
{
if(res.id != null)
{
lstId.add(res.id) ;
}
}
}
for(Restintegration__c res: Trigger.old){
List<Restintegration__c > existoppList = [Select Id from Restintegration__c where id in = lstId];
delete existoppList;
}
}
List<Id> lstId = new List<Id>();
if(trigger.isupdate)
{
for(Restintegration__c res : trigger.new)
{
if(res.id != null)
{
lstId.add(res.id) ;
}
}
}
for(Restintegration__c res: Trigger.old){
List<Restintegration__c > existoppList = [Select Id from Restintegration__c where id in = lstId];
delete existoppList;
}
}
private class testres {
static testMethod void mytestres() {
// Setup the Restintegration__c record
Restintegration__c rese = new Restintegration__c ();
rese.name = 'Deep';
insert rese ;
rese.name = 'San';
update rese;
}
}
after created class click on "run test" your trigger coverage has been reduce
All Answers
private class testres {
static testMethod void mytestres() {
// Setup the Restintegration__c record
Restintegration__c rese = new Restintegration__c ();
rese.name = 'Deep';
insert rese ;
rese.name = 'San';
update rese;
}
}
after created class click on "run test" your trigger coverage has been reduce
Below code should be helpful for you.
@isTest
public class DeleteresTest{
public static testMethod void test1(){
Restintegration__c rst = new Restintegration__c();
rst.Name = 'Test record1'; // write this line if Name field is not autonumber.
// define value for all required fields as defined for Name field.
insert rst;
update rst;
}
}
have a small doubt ..
In above code we are not refering any code from Trigger in Test class then How it covers the code coverage..
once I was executed my Trigger, then code coverage was reached to 100% ..plz explain me...How it possible...
Thanks a lot Now I got it...