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
GurunathGurunath 

Test Class Help

Any one help me writing test class for this........

 

public with sharing class ExpenseKeyWrapper
{
public Integer key {get; set;}
public Expense__c expense {get; set;}

public ExpenseKeyWrapper(){}

public ExpenseKeyWrapper(Integer inKey, Expense__c inExpense)
{
key=inKey;
expense=inExpense;
}
}

Best Answer chosen by Admin (Salesforce Developers) 
cmoylecmoyle

Something like this should be sufficient:

public class ExpenseKeyWrapperTest{
	
	static testMethod void testConstructor(){
		Integer inKey = 52;
		Expense__c expense = createExpense();
	
		ExpenseKeyWrapper eWrapper = new ExpenseKeyWrapper(inKey, expense);
		
		System.assertEquals(inKey, eWrapper.key);
		System.assertEquals(expense, eWrapper.expense);
	}
	
	private static Expense__c createExpense(){
		//Create a dummy expense record here
		Expense__c expense = new Expense(Name = 'Test Expense');
		insert expense;
		return expense;
	}
}

 

All Answers

cmoylecmoyle

Something like this should be sufficient:

public class ExpenseKeyWrapperTest{
	
	static testMethod void testConstructor(){
		Integer inKey = 52;
		Expense__c expense = createExpense();
	
		ExpenseKeyWrapper eWrapper = new ExpenseKeyWrapper(inKey, expense);
		
		System.assertEquals(inKey, eWrapper.key);
		System.assertEquals(expense, eWrapper.expense);
	}
	
	private static Expense__c createExpense(){
		//Create a dummy expense record here
		Expense__c expense = new Expense(Name = 'Test Expense');
		insert expense;
		return expense;
	}
}

 

This was selected as the best answer
GurunathGurunath

Thanx for ur help...............