You need to sign in to do that
Don't have an account?

Test Method Passed But shows error on Class??
Hi,
I have a trigger on Opportunity which fires once opportunity stage = closed won. My Test method passes but shows error on class?
/* Author: Mahfuz Choudhury Date: 13.09.13 TestClassName:TestCloneOppLineItem on Opportunity */ @isTest(seeAllData=true) private class TestCloneOppLineItem{ static testMethod void TestOppMethod() { List<Contact> contlist = new List<Contact>{}; //Start of the test execution Test.starttest(); //create a new account to associate with the opportunity Account a = new Account(Name = 'Test Account'); insert a; //Create a contact to assign as primary contact role Contact con = new Contact(FirstName = 'Maf', LastName = 'Sample', AccountId = a.Id); Contact con1 = new Contact(FirstName = 'Lewis', LastName = 'Test', AccountId = a.Id); contlist.add(con); contlist.add(con1); insert contlist; //Select A Standard pricebook for the product Pricebook2 standardPb = [select id, name, isActive from Pricebook2 where IsStandard = true limit 1]; //Create a Test PriceBook for OpportunityLineItem Pricebook2 pbk = new Pricebook2 (Name='Test Pricebook Entry 1',Description='Test Pricebook Entry 1', isActive=true); insert pbk; //Insert a new Product for test class Product2 prd = new Product2 (Name='Premium Product',Description='Test Product Entry 1',productCode = 'ABC', isActive = true); insert prd; //Insert a new Pricebook entry PricebookEntry pbe = new PricebookEntry (Product2ID=prd.id,Pricebook2ID=standardPb.id,UnitPrice=50, isActive=true,UseStandardPrice=false); insert pbe; //create a new opportunity to test Opportunity opp = new Opportunity(); opp.Name = 'Test Opportunity'; Opp.AccountId = a.id; Opp.StageName = 'Closed Won'; Opp.Type = 'Existing Business'; Opp.CloseDate = Date.today()+2; insert opp; OpportunityLineItem OLI = new OpportunityLineItem(); OLI.Quantity = 2; OLI.UnitPrice = 5.00; OLI.OpportunityId = Opp.id; //OLI.ProductId = pbe.Id; OLI.PricebookEntryId = pbe.id; insert OLI; //creating opportunity contact role and make it primary OpportunityContactRole ocr = new OpportunityContactRole(OpportunityId = Opp.Id, ContactId = Con.Id, IsPrimary = true); insert ocr; System.assertEquals('Closed Won',Opp.StageName); System.assertEquals(Opp.IsOnlineOrder__c, false); Opp.IsOnlineOrder__c = true; Update Opp; System.assertEquals(Opp.IsOnlineOrder__c, true); Test.stopTest(); } }
Can I get some help on this plz...
Hi Guys, The following class is getting 100% Coverage if anyone needs it:
All Answers
My Trigger fires when opportunity stage name=closed won (after insert, after update)
It creates a custom object record called salesA_c which is associated with opportunity product
It also create another record on custom object named Delivery_c if IsOnlineDelivery(custom field on opportunity) = true.
when I run my test class on developer console:
I see a failure sign on my test log but when I expand it or go debug log it shows test method passed and a green tick next to it.
when I go to Develop->apex class it says test class failed, test nethod passed!!
Any ideas would be appreciated....
Add try catch block as below
try{
//Your code
}
Expection(expection e){
}
Hi,
This test class is giving me real pain now!! Now I am getting the following error:
My trigger is below:
And Test Class is below:
Can Anyone figure out what's happening there??
Or any alternative to get 100% cover??
I have fixed the error since I was trying to query sales agreement object without inserting a sales agreement. I have inserted a sales agreement once Opportunity is updated and also inserted a delivery. But still it's not giving me enough coverage, I am getting only 62%, Which I was getting anyway even before inserting these two records. Also, Winter 14 you can't view which part of class is not covered by test class as well!! So, I am a bit stuck here. Any suggestion???
Hi Guys, The following class is getting 100% Coverage if anyone needs it: