+ Start a Discussion
udayarangareddy mekalaudayarangareddy mekala 

Trigger Test Class1

HI
How to cover the soql query in the testclass.There is a SOQL query ,FOReach loop after that every record add to the map variable
map<string,string> vals = new  map<string,string>();
list<Account> list =[SELECT Name,Id FROM Account];
for(contact ct : list){
          vals.put(u.Id,u.Name);
     } 
The above one is the trigger code.please give me the solution how to cover that code in test classe.

Thanks&Regards
Rangareddy
Best Answer chosen by udayarangareddy mekala
ManojjenaManojjena
Hi udayarangareddy mekala,

In your test method just insert account keep in mind  all mandate fields you need to give .
 
@isTest
pubblic class TestTrigger {
  private static testMethod void unitTest(){
   Account acc=new Account();
   acc.Name='TestAccount';
insert acc;
acc=[SELECT id,Name FROM Account WHERE Id =:acc.Id];
System.assertEquals(acc.Name,'TestAccount');

}

}
Please check belwo link it will help you to built few concepts of test class .
http://manojjena20.blogspot.in/2015/06/tips-and-tricks-for-test-class.html
Let me know if it helps !!
Thanks
Manoj
 

All Answers

ManojjenaManojjena
Hi udayarangareddy mekala,

In your test method just insert account keep in mind  all mandate fields you need to give .
 
@isTest
pubblic class TestTrigger {
  private static testMethod void unitTest(){
   Account acc=new Account();
   acc.Name='TestAccount';
insert acc;
acc=[SELECT id,Name FROM Account WHERE Id =:acc.Id];
System.assertEquals(acc.Name,'TestAccount');

}

}
Please check belwo link it will help you to built few concepts of test class .
http://manojjena20.blogspot.in/2015/06/tips-and-tricks-for-test-class.html
Let me know if it helps !!
Thanks
Manoj
 
This was selected as the best answer
udayarangareddy mekalaudayarangareddy mekala
hi
 if(newvals.severity != oldvals.Serverity){
                    Account acc = new Account();
                         acc.Field__c = 'Severity';
                         acc.New_Value__c= newvals.Severity;
                         acc.Old_Value__c= oldvals.Severity;
                         acc.Id__c = newvals.id;
                         ac.add(acc);

For above code how to write the test class.
Thnks&Regards
ranga