You need to sign in to do that
Don't have an account?
Dan Wuensch
Advanced Apex Specialist - Error - Increase test coverage with unit tests
On Step 5 of Advanced Apex Specialist (Increase test coverage with unit tests), I am getting the following error when checking the challenge:
Challenge Not yet complete... here's what's wrong:
Ensure that you create an instance of product2Extension.
Reviewing the logs seems to point to a problem in a different area than testing Product2Extension.
"Assertion Failed: Expected: 10, Actual: 20" - TestDataFactory.VerifyQuantityOrdered line 15
My unit tests that use VerifyQuantityOrdered as requested pass and are working as intended. My debug statements in TestDataFactory for setting up test data and in the unit test in OrderTests are not being logged out in this anonymous block execution, pointing to a direct invocation of TestDataFactory.VerifyQuantityOrdered directly by the Trailhead anonymous Apex, passing two Products and a qtyOrdered value of 20. The first Product passed has a Quanity_Ordered__c value of 0 and the updated product passed has a Quanity_Ordered__c value of 10. Since the qtyOrdered passed is 20, the expectation is:
public static void VerifyQuantityOrdered(Product2 originalProduct, Product2 updatedProduct, Integer qtyOrdered) {
System.assertEquals(updatedProduct.Quantity_Ordered__c, (originalProduct.Quantity_Ordered__c + qtyOrdered));
}
0 + 20 is not equalling 10 as expected. It seems to me as though the anonymous block in this step is passing the wrong value for updatedProduct.Quantity_Ordered__c.
Any recommendations?
Challenge Not yet complete... here's what's wrong:
Ensure that you create an instance of product2Extension.
Reviewing the logs seems to point to a problem in a different area than testing Product2Extension.
"Assertion Failed: Expected: 10, Actual: 20" - TestDataFactory.VerifyQuantityOrdered line 15
My unit tests that use VerifyQuantityOrdered as requested pass and are working as intended. My debug statements in TestDataFactory for setting up test data and in the unit test in OrderTests are not being logged out in this anonymous block execution, pointing to a direct invocation of TestDataFactory.VerifyQuantityOrdered directly by the Trailhead anonymous Apex, passing two Products and a qtyOrdered value of 20. The first Product passed has a Quanity_Ordered__c value of 0 and the updated product passed has a Quanity_Ordered__c value of 10. Since the qtyOrdered passed is 20, the expectation is:
public static void VerifyQuantityOrdered(Product2 originalProduct, Product2 updatedProduct, Integer qtyOrdered) {
System.assertEquals(updatedProduct.Quantity_Ordered__c, (originalProduct.Quantity_Ordered__c + qtyOrdered));
}
0 + 20 is not equalling 10 as expected. It seems to me as though the anonymous block in this step is passing the wrong value for updatedProduct.Quantity_Ordered__c.
Any recommendations?
All Answers
I would check your method, OrderUpdate_UnitTest, in OrderTest. I assume you are calling that VerifyQuantityOrdered method from there, be sure you are re-querying and iterating over the updated Product2 records as you are calling that method so that the Quantity_Ordered__c is not still 0.
Each time you are creating a Product, you loop through every product family and set the Family field. What ends up happening is each of your products has a Family value of the last picklist entry in that list. Instead, each Product you create should use the next Family value in the list:
First product created - first family picklist value
Second product created - second family picklist value
...
You can debug out each product's Family value before adding it to prodList to ensure that the Family cycles values each time. Beware of overrunning the buffer of available Family values when there is a larger number of Products being created than there are available Family values.
Hope this helps!
I find out Id 0F90N0000007riASAQ is related to object CollaborationGroup.
Here are my codes, any idea?
I have completed the Multiple choice questions for Platform Developer 2 as well as the 4 super badges. How do i link Webaccessor account to Trailhead? Has anyone got any email from salesforce after they completed the 4 super badges?
Hope this helps, also I am preparing for Platform Developer 2 multiple choice questions, any tips for prepartion? Thanks.