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
Ashok S 7Ashok S 7 

How can the following error this problem

hai guys,
when i am writing the test class controller it is getting  following errors

controller
---------------------------
public class Advanced_Dashboard1 {

    public list<Case> getCase1() {
        return [select Status,Subject from case where contact.name = 'Smith' and Status != 'Closed' limit 5];
    }


    public string getContactname() {
        return 'Smith';
    }

}

testclass
------------------------
@isTest
public class Test_Advanced_Dashboard1 
{
    //calling controller class into the test class
    Advanced_Dashboard1 ad = new Advanced_Dashboard1();
    list<case> caselist = [select Status,Subject from case where contact.name = 'Smith' and Status != 'Closed' limit 5];
    //calling methods into the testclass
    ad.getCase1();
    ad.getContactname();
}

when i saving the test testclass following error is occuring
Method must define a body 
i did not why it is coming .please help me slove this problem.
 
Alexander TsitsuraAlexander Tsitsura
Hi Ashok,

You need put test to apex method
 
@isTest
public class Test_Advanced_Dashboard1 
{
  @isTest static void test1() {
      //calling controller class into the test class
      Advanced_Dashboard1 ad = new Advanced_Dashboard1();
      list<case> caselist = [select Status,Subject from case where contact.name = 'Smith' and Status != 'Closed' limit 5];
      //calling methods into the testclass
      ad.getCase1();
      ad.getContactname();
  }
}

As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you.

Thanks,
Alex