You need to sign in to do that
Don't have an account?
symantecAP
need help with Test Class
Hi Here is my code and test class so far. please help me cover this as its not covering any class
public class ProductPriceBook23 { public class productInfo { public Product2 prod{get; set;} public List<PriceBookEntry> pbes {get; set;} public productInfo() { pbes = new List<PriceBookEntry>(); } } public List<ProductInfo> products {get; set;} public ProductPriceBook23() { products = new List<productInfo >(); Map<Id, productInfo> pInfoMap = new Map<Id, productInfo>(); for (PricebookEntry pEntry :[Select id, unitPrice, product2Id, product2.Name, product2.Description, product2.Family,product2.ATFE_Status__c, product2.ProductCode, pricebook2id, pricebook2.name from PricebookEntry where product2.ATFE_Product_Region__c='NA' and product2.Family= 'PRODUCT' and pricebook2.IsActive=true and Pricebook2.name='NA LA (USD)' LIMIT 1000 ]) { ProductInfo pInfo = new ProductInfo(); if(!pInfoMap.containsKey(pEntry.product2Id)) { pInfo.prod = new Product2(id=pEntry.product2Id, Name=pEntry.product2.Name, Description=pEntry.product2.Description, Family=pEntry.product2.Family,ATFE_Status__c=pEntry.product2.ATFE_Status__c, ProductCode=pEntry.product2.ProductCode); pInfo.pbes.add(pEntry); pInfoMap.put(pEntry.product2Id, pInfo); } else { pInfo = pInfoMap.get(pEntry.product2Id); pInfo.pbes.add(pEntry); } } products = pInfoMap.values(); } }
and the test class is
@isTest private class testpricebook{ private static testmethod void testpb(){ PriceBookEntry pbe1=[Select id,unitprice,Product2Id,Product2.Name,Pricebook2.name, Product2.Description,Product2.Family from PriceBookEntry where product2.ATFE_Product_Region__c='NA' and product2.Family='PRODUCT' limit 1]; Product2 prod = new Product2(Name='AT-iMG008GNB-10',Description='Grounded UPS without battery. Battery must be ordered separetly'); string pricebook = pbe1.Pricebook2.name; //ProductPriceBook23.Productinfo('01t200000022vPnAAI','USD 47.00','AT-iMG008GNB-10',pricebook); } }
Please help
You commented out your constructor for the class you wish to test.
For creating test class you can look at structure of a Apex Test Class
http://forceschool.blogspot.com/search/label/Test%20Apex
Hope it will help you.
Yes coz it gives this error
That's because it wasn't written correctly. It's supposed to call a constructor, not a normal method. I should have read closer, but ProductPriceBook23 doesn't have a method called Productinfo.
Hi Damien
It worked. But it covers 80%. What possible things can be done to make it more durable
Thanks
Adil
Create objects that will allow it to fall into all of the different if statements.
Can you give me a prototype of it. creating objects
You already did it once.
How do I accomplish for "IF" statements
If you want to test any class and any condition in it then your data should be such that the condition satisfies.
Ex :
If i have a condition
if(Employee.Salary__C > 25000)
then my test data should create a data where Salary for employee more than 25000 so that condition satisfies. Similarly you need to create data to satisfy your condition.
sure shashi lemme try this. .