You need to sign in to do that
Don't have an account?
JaimeBid
My question is because I do not see any changes, whether I use true or false on that parameter: System.Assert(false);
Thanks in advance!
What is doing " System.Assert(false) " here?
Hi all!
My first question, apologies in advance if answer is clear, but I am beginning with APEX, and I am a bit stuck here.
What does "System.Assert(false);" is doing exactly here?
try{ ContactsDML.databaseMethodDML(); System.Assert(false); } catch(DMLException e){ System.assert(e.getMessage().contains('Required fields are missing: [LastName]: [LastName]')); }I am within a class method, calling another class for the test, which results in an error (as stated in the message).
My question is because I do not see any changes, whether I use true or false on that parameter: System.Assert(false);
Thanks in advance!
System.Assert accepts two parameters, one (mandatory) which is the condition to test for and the other a message (optional) to display should that condition be false.
System.AssertEquals and System.AssertNotEquals both accepts three parameters; the first two (mandatory) are the variables that will be tested for in/equality and the third (optional) is the message to display if the assert results in false.
Now, testing best practices state that you should assert some condition but also output a “console” message that shows the values of each of the operands. This certainly helps you debug unit tests when asserts are failing
Here is an example showing proper usage
Let me know if this helps, if it does, please close the query by marking it as solved. It may help others in the community. Thank You!
My specific question is what that piece of code ( System.Assert(false); is doing on the whole picture, why it is there because I do not see any changes wether I set it to true to false.
So, by your answer, I understand that it is not doing anything, and the code should be like this instead
Did I understand you right?
Thanks, I have a second thought
What about "System.Assert(false)" is within the try statement to ensure force error