You need to sign in to do that
Don't have an account?

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?
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?
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
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