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
Hema!Hema! 

class for test

i covered 62%  help me


public class mySecondController {
    Account account;

    public Account getAccount() {
        if(account == null) account = new Account();
        return account;
    }

    public PageReference save() {
        // Add the account to the database. 
        insert account;
        // Send the user to the detail page for the new account.
        PageReference acctPage = new ApexPages.StandardController(account).view();
        acctPage.setRedirect(true);
        return acctPage;
    }
}
=======================
@isTest
private class mySecondController_Test{
  static testMethod void test_getAccount_UseCase1(){
    mySecondController obj01 = new mySecondController();
    obj01.getAccount();
  }
  static testMethod void test_save_UseCase1(){
    mySecondController obj01 = new mySecondController();
    obj01.save();
  }
}


Thanks in Advance

 
Best Answer chosen by Hema!
DeveloperDeveloper
@isTest
private class mySecondController_Test{
  static testMethod void test_getAccount_UseCase1(){
    mySecondController obj01 = new mySecondController();
    obj01.getAccount();
  }
  static testMethod void test_save_UseCase1(){
    //Account obj = new Account(Name = 'TestAcc',Site='Test123');
    //insert obj;
    
   // Pagerefernce pageRef = new Pagereference('/'+obj.id);
   // Test.setCurrentPage(pageRef);
   
    //ApexPages.StandardController sc = new ApexPages.StandardController(obj);
    mySecondController obj01 = new mySecondController();
     Account obj = obj01.getAccount();
     obj.Name = 'TestAcc';
     obj.Site='Test123';
    obj01.save();
  }
}

 

All Answers

Deepak Pandey 13Deepak Pandey 13
Try this,
@isTest
private class mySecondController_Test{
  static testMethod void test_getAccount_UseCase1(){
    mySecondController obj01 = new mySecondController();
    obj01.getAccount();
  }
  static testMethod void test_save_UseCase1(){
    Account obj = new Account(Name = 'TestAcc');
    insert obj;
    mySecondController obj01 = new mySecondController();
    Pagerefernce pageRef = new Pagereference('/'+obj.id);
    Test.setCurrentPage(pageRef);
    obj01.save();
  }
}     
DeveloperDeveloper
@isTest
private class mySecondController_Test{
  static testMethod void test_getAccount_UseCase1(){
    mySecondController obj01 = new mySecondController();
    obj01.getAccount();
  }
  static testMethod void test_save_UseCase1(){
    //Account obj = new Account(Name = 'TestAcc',Site='Test123');
    //insert obj;
    
   // Pagerefernce pageRef = new Pagereference('/'+obj.id);
   // Test.setCurrentPage(pageRef);
   
    //ApexPages.StandardController sc = new ApexPages.StandardController(obj);
    mySecondController obj01 = new mySecondController();
     Account obj = obj01.getAccount();
     obj.Name = 'TestAcc';
     obj.Site='Test123';
    obj01.save();
  }
}

 
This was selected as the best answer