+ Start a Discussion
sfdotcomsfdotcom 

Apex test class for controller

Hi, I need test class for below controller.

public class Sum
{
 public integer first { get; set;}
  public integer second { get; set;}
  public integer result {get; set;}
  public void add()
  {
   result = first + second ;
  }
 public void sub()
  {
   result = first - second ;
   }
 public void mul()
  {
   result = first * second ;
   }
public void mod()
 {
   result = first / second ;
 }
  }
Best Answer chosen by sfdotcom
SaranSaran
Hi,

Hope this below test class code should cover you class
 
@isTest
public class sum_Test

public static testMethod void method1()
{
	Sum sumInstance = new Sum();
	sumInstance.first = 10;
	sumInstance.Second = 2

	sumInstance.add();
	system.assertEquals(sumInstance.result , 12);

	sumInstance.sub();
	system.assertEquals(sumInstance.result , 8);

	sumInstance.mul();
	system.assertEquals(sumInstance.result , 20);

	sumInstance.mod();
	system.assertEquals(sumInstance.result , 5);
}

Let us know if you have any issue.

Thanks!

 

All Answers

SaranSaran
Hi,

Hope this below test class code should cover you class
 
@isTest
public class sum_Test

public static testMethod void method1()
{
	Sum sumInstance = new Sum();
	sumInstance.first = 10;
	sumInstance.Second = 2

	sumInstance.add();
	system.assertEquals(sumInstance.result , 12);

	sumInstance.sub();
	system.assertEquals(sumInstance.result , 8);

	sumInstance.mul();
	system.assertEquals(sumInstance.result , 20);

	sumInstance.mod();
	system.assertEquals(sumInstance.result , 5);
}

Let us know if you have any issue.

Thanks!

 
This was selected as the best answer
sfdotcomsfdotcom
Thank You Saran.