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
sumit dsumit d 

AssertEqual in test class

Hi All,
My test class is given below:-
// Test class for BatchResellerPartnerToResellerCustomer
@isTest
private class BatchResellerCustomerTest {
static testmethod void TestResellerCustomer(){
// Check the API Name
Id recId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Time Rack').getRecordTypeId();
Account acc =new Account( Name = 'test' ,Customer_Type__c ='Reseller' ,recordtypeid = recId );
insert acc;
//List<Opportunity> oppList = new List<Opportunity>();
// Opportunity Name with '-'
Opportunity opp = new Opportunity();
opp.StageName = 'Sourcing Demand';
opp.AccountId = acc.id;
opp.CloseDate = System.today();
opp.Name = 'test -ExPay';
insert opp;
// Opportunity Name with ':'
Opportunity oppt = new Opportunity();
oppt.StageName = 'Sourcing Demand';
oppt.AccountId = acc.id;
oppt.CloseDate = System.today();
oppt.Name = 'test :RePay';
insert oppt;
//opportunity Name other than '-' and ':'
Opportunity oppty = new Opportunity();
oppty.StageName = 'Sourcing Demand';
oppty.AccountId = acc.id;
oppty.CloseDate = System.today();
oppty.Name = 'test Pay';
insert oppty;
test.startTest();
BatchResellerPartnerToResellerCustomer obj = new BatchResellerPartnerToResellerCustomer();
database.executeBatch(obj);
Set<Id> OppIds = new Set<Id>();
OppIds.add(opp.Id);
BatchResellerPartnerToResellerCustomer.run(OppIds);
test.stopTest();
}
}
how to put Asserts in this test class to make it better?
Any suggestions?
Best Answer chosen by sumit d
SEKAR RAJ.SEKAR RAJ.
Hi Sumit,

Opportunity opp = new Opportunity();
opp.StageName = 'Sourcing Demand';
opp.AccountId = acc.id;
opp.CloseDate = System.today();
opp.Name = 'test -ExPay';
insert opp;
// Query the inserted opportunity record
List<Opportunity> oppList = [SELECT id,Name,Stage FROM Opportunity Where Id=: opp.Id];

Here, Consider the scenario that After inserting an opportunity, the trigger will change the opportunity Stage as "Prospecting".

System.assertEquals(ExpectedResult,ActualResult); // original syntax
System.assertEquals('Prospecting','oppList[0].Stage'); 

Thanks,
SEKAR RAJ

 
 

All Answers

SEKAR RAJ.SEKAR RAJ.
Hi Sumit,

Opportunity opp = new Opportunity();
opp.StageName = 'Sourcing Demand';
opp.AccountId = acc.id;
opp.CloseDate = System.today();
opp.Name = 'test -ExPay';
insert opp;
// Query the inserted opportunity record
List<Opportunity> oppList = [SELECT id,Name,Stage FROM Opportunity Where Id=: opp.Id];

Here, Consider the scenario that After inserting an opportunity, the trigger will change the opportunity Stage as "Prospecting".

System.assertEquals(ExpectedResult,ActualResult); // original syntax
System.assertEquals('Prospecting','oppList[0].Stage'); 

Thanks,
SEKAR RAJ

 
 
This was selected as the best answer
sumit dsumit d
Thanks It helps.