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
Saikiran KolliSaikiran Kolli 

Test Class Problem for Pagereference

Hi,

My test class is not working please help me.
public  class google {

    public google(google1 controller) {

    }


    public google(ApexPages.StandardController controller) {

    }

public pagereference google() {
  return new pagereference('/apex/PlotGoogleMarker');
 
}

}







@isTest
public class googletest {
@isTest 
    static void test1() {
        PageReference ref = new PageReference('/apex/PlotGoogleMarker');
        Test.setCurrentPage(ref);
         ref = new PageReference('/apex/PlotGoogleMarker?id=');
        Test.setCurrentPage(ref);
        System.assertEquals('/apex/PlotGoogleMarker?id=recordId',Ref.getUrl());
    }
}

 
Best Answer chosen by Saikiran Kolli
Amit Chaudhary 8Amit Chaudhary 8
Please check below post to learn about test classes
1) http://amitsalesforce.blogspot.com/search/label/Test%20Class
2) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html

Please try below test class
@isTest
public class googletest {
@isTest 
    static void test1() 
	{
		Account testAccount = new Account();
		testAccount.Name='Test Account' ;
		insert testAccount;
		ApexPages.StandardController sc = new ApexPages.StandardController(testAccount);
		google obj = new google(sc);
		obj.google();
		
    }
}

Let us know if this will help you

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please check below post to learn about test classes
1) http://amitsalesforce.blogspot.com/search/label/Test%20Class
2) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html

Please try below test class
@isTest
public class googletest {
@isTest 
    static void test1() 
	{
		Account testAccount = new Account();
		testAccount.Name='Test Account' ;
		insert testAccount;
		ApexPages.StandardController sc = new ApexPages.StandardController(testAccount);
		google obj = new google(sc);
		obj.google();
		
    }
}

Let us know if this will help you
This was selected as the best answer
Saikiran KolliSaikiran Kolli
Amit,

Can you please help me test classes for the below two methods,

public integer getsizeofsr(){
        return srsize;
   }




  public PageReference closeChangeDay() {
          chnageDayFlg = false;
       return null;
   }
Amit Chaudhary 8Amit Chaudhary 8
You simply need to call like below in your test class
ClassName obj = new ClassName();
obj.getsizeofsr();
obj.closeChangeDay();

NOTE:- If that is StandardController then call like below
 
Account testAccount = new Account();
		testAccount.Name='Test Account' ;
		insert testAccount;
		ApexPages.StandardController sc = new ApexPages.StandardController(testAccount);
		google obj = new google(sc);
		obj.getsizeofsr();
        obj.closeChangeDay();

 
Saikiran KolliSaikiran Kolli
Amit,
Really appreciating your help,
I tried like this

 static void test6() {
    logView3Controller testaccount = new logView3Controller();
       

            testAccount.Name='Test Account' ;

            insert testAccount;

            ApexPages.StandardController sc = new ApexPages.StandardController(logView3Controller);

           closechangeday obj = new closechangeday(sc);

            obj.closechangeday();
     
    }


Error is       Invalid type: closechangeday


Can u plz help me.