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
Michael DsozaMichael Dsoza 

Query while writing Test class

Hii Right now I am writing test class, I want to know exact use of unit testing ?

Since as I know, It is used to check all syntax & DML operation of the application to avoid bugs or exception.

But I have one case like right now,  In account, there is two type of account named Business account & person account.

Every time we prefer Person Account & I already disable Business account while creating new account so it creates Person account by deafult.

But while writing test class I am writing like this...

acc = new Account(Firstname='manoj', Lastname='gahlot', RecordTypeId='PersonAccountRecordTypeID');

 

So please tell me am I writing correct test for the type Person account ?

kiranmutturukiranmutturu

writing a test class is to test the flow of your logic.. and at the same time you have to check for in and outs also. like if and else should be checked prior to do your prod. but as you are saying that u disabled the BA permanantly. means you will never get a BA in your org. Then you don't need to test that. but as the best practise its better to check prior assigning the recordtypeid.

Michael DsozaMichael Dsoza

Yaa Kiran, But as i mentioned the sample code, Is that correct for creating Person Account ?

& Please let me know how to test if...else condition in test class since it is not in any function.

Devendra NataniDevendra Natani

Hi,

 

Please use the sample code for test class.

 

@isTest
private class TestAccount{
public static testmethod void testPersonAccount(){

List<RecordType> lstRecordType = [select id from RecordType where  name = 'PersonAccountRecordTypeID'];

if (lstRecordType.size() > 0){
Account acc = new Account(Firstname='manoj', Lastname='gahlot', RecordTypeId=lstRecordType.get(0).id);

insert acc;

Test.startTest();
// add your logic here
Test.stopTest();
}

}
}

 Please let me know if there is any issue.