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
Jonathan Crow 6Jonathan Crow 6 

Apex Test Coverage Error on Unexpected token 'void'

I am still new to Apex testing and am trying to build a test class on the following, but keep running into the error message “Unexpected token 'void' on the second line of the test class. Can somebody tell me where I went wrong?

Here is my class:
 
public  class MyNewCaseController {
	
	public string filterId {get; set;}
	
	public MyNewCaseController(ApexPages.StandardController  ctrl){
		string filter = ApexPages.currentPage().getParameters().get('filterId');
		if (filter != null)
			filterId = filter;
	}
}

Here is my test class:
 
@isTest
public static void MyNewCaseControllerTest {
    string testFilterId = MyNewCaseController.filterId;
    
    public static void MyNewCaseControllerTest(ApexPages.StandardController  ctrl){
        string filter = ApexPages.currentPage().getParameters().get(CommunitiesCaseControllerTest.testFilterId);
        if (filter != null)
            testFilterId = filter;
    }
}
AnkaiahAnkaiah (Salesforce Developers) 
Hi Jonathan,

try something like below.
@isTest
public class MyNewCaseControllerTest {
    static testMethod void testMethod1() 
	{
	//replace the object which you want to use in filterid
		Account testAccount = new Account();
		testAccount.Name='Test Account' ;
		insert testAccount;
        test.startTest();
		
			ApexPages.StandardController sc = new ApexPages.StandardController(testAccount);
			
		test.stopTest();
    }
}

If this helps, Please mark it as best answer.

Thanks!!​​​​​​​