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

what is system.assertequal and static{}?


any one can explain me, why we use System.assertEqual() and static{ } in test class with example.

Thanks in Advance!!!
Hi Sain,

In test class, you have to use System.assertEqual() method when you want to verify (static method of the System class) the result of your tests to be sur your Apex code works like you want.

This is a example of an Apex test class :
private class ApexClass_TEST {

	static Account anAccount;
	static String theName;

	static void init(){
		theName = 'My account';

		/** Account **/
			anAccount = new Account(
				Name = theName
			insert anAccount;			

    static testMethod void myTest() {
        Account insertedAccount = [
        	SELECT Id, Name
        	FROM Account
        	WHERE Id = :anAccount.Id

        System.assertEquals(theName, insertedAccount.Name);

I don't know why test method are static but it's said in the documentation. :)

Let me know if you understand my example.