By adding system.assert or system.assertEquals or system.assertNotEquals will create any impact ?


The internal mechanism is that an assert failure causes an exception to be thrown (at runtime) that is caught by the test runner and eventually reported in the test results. So the test method code essentially stops running at that line of code: later code and assertions in the test method do not run so the code that later code would invoke is no longer invoked.

The aim in tests is to end up with asserts that do not fail but that confirm that the code being tested is doing what is expected.


While adding asserts into non-test code is tempting, the exception that is thrown is not catchable in Apex. So if you have a try/catch block (such as one that tries to convert an exception into an ApexPages.Message) it will be bypassed for the assertion failure which is probably not what you want. So if you want to have assertion methods, create your own and throw your own custom exception.

  • I think it's important to note that the assertions will still throw exceptions outside a test context. So they will have an impact on an apex class that includes them if the assertion fails. If this is occurring in production outside a test throwing a custom exception may be more appropriate. – Daniel Ballinger Jun 4 '15 at 9:04
  • 1
    @DanielBallinger Good point. I've added a bit on that subject. – Keith C Jun 4 '15 at 9:19

The actual purpose of test class is to test the functionality that you have implemented in apex class. so we create test data and execute the functionality. at the end we must test the functionality by comparing expected result with actual result with the help of assert statement.

The assert statement are used to test the expected result against actual result. and if assert statement are failing, this means your functionality is not working correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.