You need to sign in to do that
Don't have an account?
Test records are not inserted
Hi all,
I have a test class where in i am trying to insert the test record but i doubt on they are being inserted properly
below is my code
Also i have mentioned an asset statement to check if the record is inserted successfully or no
but i dont know how do i check whether that asset statement is executed successfully or no as it does not appear in the logs
Any help would be appreciated
thanks
I have a test class where in i am trying to insert the test record but i doubt on they are being inserted properly
below is my code
@isTest public class VisitHandler_Test { //create test data static testMethod void createTestData() { Account acc=new Account(Name='Test Account',Channel__c='On-trade', Premise_Type__c='Brown Café'); insert acc; List<POSItemAccountLink__c> posLst=new List<POSItemAccountLink__c>(); POSItem__c posItem=new POSItem__c(name='test item',type__c='Killer Item'); insert posItem; for(Integer i=0;i<2;i++) { POSItemAccountLink__c pos=new POSItemAccountLink__c(); pos.Account__c=acc.Id; pos.POSItemAccountLink__c=posItem.id; posLst.add(pos); } insert posLst; //assert System.assertEquals(posItem.Name,'test item'); } }
Also i have mentioned an asset statement to check if the record is inserted successfully or no
but i dont know how do i check whether that asset statement is executed successfully or no as it does not appear in the logs
Any help would be appreciated
thanks
Also, if a system.assert() fails, the transaction stops immediately - that's how you know it was successful, because it doesn't stop.
If an assert statement doesnt execute succesfully in test class, it will throw an error.
If you are not getting an error in the debug log, it means the assert executed successfully.
In your code, if you want to check if the record has been inserted successfully, you can use the statement like below. This will insure that posItem has ID in it, which means it inserted fine.
If assert passes without an error, your data is entered properly. You can do a system.debug(posLst) to make sure that the items have ids associated with them.
Thankyou for stopping by and replying to my query..
well the actual problem was that the lst which was suppose to invoke the trigger was written before the insert posLst; statement due to which the posLst was not covering the code in my Handler class.So i had to write it after all the insert statements like this
This solved my query
According to the above code,the two inserts prior to test.start method when mentioned inside test.startTest() throws an error stating they are not inserted.Also they are the master object records.Can this may be teh reason?
Thanks