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
Sajila KadayaprathSajila Kadayaprath 

What is the use of System.AssertEquals(1,1)

I could see the usage of System.AssertEquals(1,1) in some codes available over internet. 
Can anybody explain for what it is used for?

Thanks,
 
Best Answer chosen by Sajila Kadayaprath
Bhanu MaheshBhanu Mahesh
That statement is nothing. This is just trying to pass a method without checking the result from the code we are testing.

System.AssertEquals(1,1) always return true whatever the result from the code. Then test method will always get passed if there is no exception from the code. 

If we use these types of assertions implies that we are just concentrating on the code coverage not on the result.

Regards,
Bhanu Mahesh

All Answers

Bhanu MaheshBhanu Mahesh
Hi Sajila,
system.assertEquals method  is used to verify that the expected result is returned

System.assertEquals() is used to validate two values are equal. Basically it is used in test method. This method asserts that the first two arguments, x and y are the same, if they are not a runtime exception is thrown.

Please refer the below link 
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_example.htm

Regards,
Bhanu Mahesh
Bhanu MaheshBhanu Mahesh
Usage is salesforce will consider a testmethod is passed only if Assertion is passed. Otherwise the method will be failed.
Means the code you are testing is not giving you the expected result. This may be due to problem in your code or with the data you are testing.

You cannot deploy a test class to production if it is failed.


You have to correct the code or data to make the test class pass with expected results which can be checked with System.assertEquals by passing the expexted result and the result from the code as parameters.

So salesforce ensures the corect code being deployed to production after being tested properly.  

Regards,
Bhanu Mahesh
Bhanu MaheshBhanu Mahesh
That statement is nothing. This is just trying to pass a method without checking the result from the code we are testing.

System.AssertEquals(1,1) always return true whatever the result from the code. Then test method will always get passed if there is no exception from the code. 

If we use these types of assertions implies that we are just concentrating on the code coverage not on the result.

Regards,
Bhanu Mahesh
This was selected as the best answer