1

私はapexで休息サービスの単体テストを書いています

私のテストクラスは

global class Feedpost9 {

    // your methods here...

    static testMethod void testRest() {
        // set up the request object
        System.RestContext.request = new RestRequest();
        RestContext.request.requestURI = '/v.9/notifications/preferences/ritesh';
        // Invoke the method directly
        Member__c member=new Member__c(name='ritesh');
        insert member;

        Notification_Settings__c no=new Notification_Settings__c(member__c=member.Id);
         no.Event__c='Category|Cloud Foundry' ;
         no.Event_Per_Member__c='12';
         insert no;


        NotificationRestService.retrievingNotificationSettings();

        RestContext.request.requestURI = '/v.9/notifications/preferences' ;

        NotificationRestService.retrievingNotificationSettings();
        RestContext.request.requestURI ='/v.9/notifications/preferences/ritesh.xml';
NotificationRestService.retrievingNotificationSettings();
    }
}

テスト ユニットがこの時点に到達すると、エラー RestContext.request.requestURI = '/v.9/notifications/preferences' が発生しました。

        NotificationRestService.retrievingNotificationSettings();

エラーは

System.NullPointerException: null オブジェクトを逆参照しようとしています Class.NotificationRestService.retrifyingNotificationSettings: 行 46、列 1 Class.Feedpost9.testRest: 行 23、列 1

このエラーが発生しているセグメントは

 List<Notification_Settings__c> note1=[SELECT id,name,Member__r.name,Do_not_Notify__c,Event__c,Event_Per_Member__c,Notification_Method__c from Notification_Settings__c WHERE Member__r.name= :userName Limit 1];
Notification_Settings__c note;

if(note1 !=null )
{if(note1.size() >0)
note=note1.get(0);
}

そしてエラーは行にあります次の行と最初に if statement.query が空のリストを返す必要があります。誰か助けてください!!

4

1 に答える 1

0

@isTest(SeeAllData=true) アノテーションを追加

@isTest(SeeAllData=true)
global class Feedpost9 {

}
于 2013-01-27T06:54:00.823 に答える