0

I have rewritten a class whose testing was originally within the class and not a separate test class.

As it is right now, my test code looks like this :

@isTest
private class TestCSHOrgModelQuarterly {
        static Id getRecordTypeId(String sObjectType, String Name) {
        return [select id from recordtype where sobjecttype=:sObjectType and name=:Name limit 1].id;
    }
        static final Id Org_Rectype = getRecordTypeId('Organization_Model__c','Global');
        static final Id A_MM_Rectype = getRecordTypeId('Account','Multi');

        Account Acc1;
        Organization_Model__c Org1;

        String u;  // Unique number for this test run.

        TestCSHOrgModelQuarterly() {

            // Create a unique string for this test so we're never confused with existing data.
            u = Datetime.now().millisecond().format();

            Acc1 = new Account(Name=u+'Test1', recordtypeid=A_MM_Rectype, status_corporate_travel__c = 'Client', ownerid=UserInfo.getUserId(), billingcountry='USA');
            insert Acc1;  

            Org1 = new Organization_Model__c(Name=u+'Test2', recordtypeid=Org_Rectype, Org_Model_CSH_to_be_completed_by__c = UserInfo.getUserId(), Account__c = Acc1.id, Org_Model_CSH__c = 'Quarterly');
            insert Org1;            
            }

        static testMethod void testReview() {
        // Reduce the number of message we get during debugging.
        system.debug(Logginglevel.DEBUG);

        // All we're really doing is setting up the data, calling the routine, and checking the results.
        TestCSHOrgModelQuarterly x = new TestCSHOrgModelQuarterly();

        Date tod = Date.Today();
        // Calculate the dates we might use for AM_Completion depending on record type.
        Date AM_Date_10 = Date.newInstance(tod.addMonths(1).year(),tod.addMonths(1).month(),10);
        Date AM_Date_15 = Date.newInstance(tod.addMonths(1).year(),tod.addMonths(1).month(),15);        

        test.startTest();
        CSHOrgModelQuarterly CSHR = new CSHOrgModelQuarterly();

        String xxx = CSHR.doReview(true);

        test.stopTest();
        CSH_New__c Org1Csh = [select id, Due_Date__c from CSH_New__c where Organization_Model__c = x.Org1.id ];
    system.assertEquals(AM_Date_10, Org1Csh.Due_Date__c);
         }
}

I am getting this error when attempting to save it :

unexpected token: 'x.Org1.id' 

Thank you very much for any advice you can give.

2 Answers 2

4

Because your testMethod is static it can't access member or properties from the TestCSHOrgModelQuarterly directly. You need to reference them via an instance of TestCSHOrgModelQuarterly.

E.g.

CSH__c Org1Csh = [select id, Due_Date__c from CSH__c where Organization_Model__c = :x.Org1.id ];

Note: It isn't really clear from your sample code if the class name is TestCSHOrgModelQuarterly (based on the class defintion) or TestData (based on the constructor). I think you need to replace the occurrences of TestData with TestCSHOrgModelQuarterly.

4
  • I followed your advice and referenced the instance and also replaced all occurances of TestData with TestCSHOrgModelQuarterly - but I'm still getting an unexpected token : 'TestCSHOrgModelQuarterly.Org2.id' error coming back. It's really driving me crazy. I updated the code in the main post to show what it looks like now. Thank you very much for your help. I really appreciate it.
    – Zoom_v
    Commented Dec 4, 2013 at 22:07
  • 1
    @Zoom_v you want the instance of TestCSHOrgModelQuarterly which is x in your example. E.g where Organization_Model__c = :x.Org1.id Commented Dec 4, 2013 at 22:18
  • Daniel - first of all thank you very much for all your help. I really appreciate it. I have tried to use the instance as you suggested but I'm getting an unexpected token error for that line. I put the current code up on the main post. It's the same as it was before except with the addition of the x in the org1.id reference but I thought I would put it there in case I missed something to mention. Thank you very much again.
    – Zoom_v
    Commented Dec 5, 2013 at 17:06
  • 1
    Your missing the : that should proceed it in the SOQL statement. Commented Dec 5, 2013 at 18:54
2

It looks like you have an extra closing bracket (}) before that test method. Try removing that and see what happens.

You are also missing a closing bracket at the very end of the class but that might of been a typo when creating this question.

6
  • Thank you very much for your response @BarCotter. I removed the closing bracket and put another one at the bottom. But now I'm getting an unexpected token: 'Org2.id' error on my query towards the bottom. I'm guessing it's something just as silly as the previous one, but I can't find it. Do you have an idea on that ? Thanks again.
    – Zoom_v
    Commented Dec 4, 2013 at 20:05
  • There is no reference to Org2 in the code you supplied in the question. Im guessing that you have changed the code since posting the question.
    – BarCotter
    Commented Dec 4, 2013 at 20:11
  • oh, you're right - I had the wrong version of the code in the post. I updated the post and the version I am having problems with is on there now. I'm really sorry about that ! The Org1.id reference at the bottom is what is producing an unexpected token error. Sorry again.
    – Zoom_v
    Commented Dec 4, 2013 at 20:38
  • I'm also getting an Invalid contructor name : TestData on my line where it is initially referenced TestData() {
    – Zoom_v
    Commented Dec 4, 2013 at 21:10
  • 1
    Daniel Ballingers answer explains those problems
    – BarCotter
    Commented Dec 4, 2013 at 21:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .