function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
HCrousePDXHCrousePDX 

Help Test code not making sense.

I have something strange happening in my test code and I can't figure out what's happening.

 

I have to following code:

//other code to create O1 exists above. 

ApexPages.StandardController sc = new ApexPages.standardController(O1);

    cntrCreateCompanyProduct CCP = new cntrCreateCompanyProduct(sc);

    CCP.newCP(); //creates a new ComProd varible and loads it.

    if(CCP.ComProd != null) system.debug('testing comp is not null');

    System.AssertEquals(CCP.ComProd,null);

 

So I see the debug message in my debug log, which means that CCP.ComProd is not null however the Assert is firing causing my test code to fail at this point?

 

I'm not sure what I'm missing.

Best Answer chosen by Admin (Salesforce Developers) 
Bhawani SharmaBhawani Sharma
Your assert statement is not correct. You are comparing it with Null. Update it to:
System.AssertNotEquals(CCP.ComProd,null);

All Answers

Abhi_TripathiAbhi_Tripathi

Hi,

 

That in red if its a method so do something just above to it, because its unable to find anything, thats why its showing everything null

 

 

 

ApexPages.StandardController sc = new ApexPages.standardController(O1);

    cntrCreateCompanyProduct CCP = new cntrCreateCompanyProduct(sc);

 

   /* INSERT YOUR RECORD HERE , EXACT CONDITION FOR THE METHOD "newCP" */

 

    CCP.newCP(); //creates a new ComProd varible and loads it.

    if(CCP.ComProd != nullsystem.debug('testing comp is not null');

    System.AssertEquals(CCP.ComProd,null);

 

 

don't forget to mark correct with kudos (Start) if the solution helps you

 

 

Bhawani SharmaBhawani Sharma
Your assert statement is not correct. You are comparing it with Null. Update it to:
System.AssertNotEquals(CCP.ComProd,null);
This was selected as the best answer
HaroldHarold

Thank you, after reading your post I went and did some more research.  I assumed system.Assertequals(comProd,null); would fire if comProd == null.  But I guess it's the opposite and it fires if the condition is false.

 

 

Thanks Again.  I don't see how to mark this as my solution, but it was.

 

 

Bhawani SharmaBhawani Sharma
There is a drop-down in red
"Options".
Click on it and mark it as accepted.

Regards,
Bhavi Sharma
Certified Salesforce Consultant
bhavi@simplyforce.com/bhawani.sh.sharma@gmail.com
+91-9928130589
LinkedIn |
Twitter
| Blog |
Community
www.simplyforce.com
HaroldHarold

That's what I figured but I don't have that option.

 

I can't put in a screen shot but I only have

Mark as New

Bookmark

Subscribe

 

Subscribe to RSS Feed

Email to Friend

Revoke my Kudos

 

Report Inappropriate Content.