0

Hi I am trying to pass this id through page reference to my controller for the test coerage. but this line below gives me an error saying

unexpected token: '.'

Test Class

 @IsTest

public class TestNotice_Controller {

    private static ApexPages.StandardController cont;
    Opportunity opp = new opportunity(name = 'Cart');
    string id = opp.id; 
    PageReference pg = Page.Notice;
    pg.getParameters().put('id', id);


    private static testMethod void testNew() {

        Test.startTest();
        {   

            // Initialize the controller
            Notice_Controller ln = new Notice_Controller(cont);

        }
        Test.stopTest();
    }

}

I don't understand where is the probelem. According to developer guide I am not doing anything wrong. But I don't understand why I am getting this error.

3
  • 1
    Seems like we're missing a bit of code... Can you give more context to your sample? Also, what line is it failing on? Apr 15, 2016 at 17:49
  • it is giving error on this line. pg.getParameters().put('id', id); let me update the code with entire test class
    – Ricky
    Apr 15, 2016 at 17:54
  • ok I have added that now
    – Ricky
    Apr 15, 2016 at 17:57

1 Answer 1

2

Your class should look like this. You have a lot of code outside of a function, when it should be inside.

@IsTest
public class TestNotice_Controller {

    private static testMethod void testNew() {
      private ApexPages.StandardController cont;
      Opportunity opp = new opportunity(name = 'Cart');

      string id = opp.id; 
      PageReference pg = Page.Notice;
      pg.getParameters().put('id', id);

      Test.startTest();
          // Initialize the controller
          Notice_Controller ln = new Notice_Controller(cont);                     

      Test.stopTest();
    }

}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.