Testing 顶点测试方法误差

Testing 顶点测试方法误差,testing,salesforce,apex-code,Testing,Salesforce,Apex Code,我们对apex测试方法有问题。我们在apex方法中有一个http请求。我必须为此创建一个测试方法。但我们有一个问题 Apex代码: public void ReceiveBestAnswer(Id repID){ reply = GlobalFunctions.getReplyCreatorDetails(repID); System.debug(reply); String bestReplyUser = reply.CreatedByI

我们对apex测试方法有问题。我们在apex方法中有一个http请求。我必须为此创建一个测试方法。但我们有一个问题

Apex代码:

public void ReceiveBestAnswer(Id repID){    
        reply = GlobalFunctions.getReplyCreatorDetails(repID);
        System.debug(reply);
        String bestReplyUser = reply.CreatedById;


        profileUser = [select Username,Email from User where Id = :bestReplyUser];
        System.debug('profileUser.Name-->'+profileUser.Username);  
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();

        req.setEndpoint('http://sandbox.v2.badgeville.com/api/berlin/b95839370dca983955e550296450ec03/activities.json');
        req.setMethod('GET');
        req.setBody('activity[verb]=receive best answer&site=www.grazitti.com&user='+ profileUser.Email );
        try {
            http.send(req);
            System.debug('res-->');
        } catch(System.CalloutException e) {
            System.debug('Callout error: '+ e);
            System.debug(res.toString());
        } 
}  
试验方法:

 public static testMethod void testReceiveBestAnswer() {        
 Reply reply = new Reply();
    String replyId = reply[0].Id;
  //  Id questionID = '906P0000000010KIAQ';
  //  String sql =  'SELECT Id, Title FROM Question';  
 //   Question[] ques = [SELECT Id FROM Question];      
 //   Question quest = ques[0];       
    BadgeVilleWebServiceCallout bv = new BadgeVilleWebServiceCallout();
    bv.badgvilleReceiveBestAnswer(replyId );

}
第2种试验方法:

 public static testmethod  void testReceiveBestAnswer1() 
     {

        ID ProfileID = [ Select id from Profile where name = 'Named Marketo Community Portal'].id;
        System.debug('ProfileID --->'+ProfileID );
        Account A1 = new Account(Name = 'Test Account');
        insert A1;        
        List<Contact> ContactList = new List<Contact>();
        Contact C1 = new Contact( AccountID = A1.id, FirstName = 'Test', LastName = 'User', 
            email = 'test-user@fakeemail.com' );
        insert C1;


        User u1 = new User( email='test-user@fakeemail.com', contactid = c1.id, profileid = profileid, 
            UserName='test-user@fakeemail.com', alias='tuser1', CommunityNickName='tuser1', TimeZoneSidKey='America/New_York', LocaleSidKey='en_US', EmailEncodingKey='ISO-8859-1',  LanguageLocaleKey='en_US', FirstName = 'Test', LastName = 'User' );
    insert u1;
    System.debug('u1--->'+u1 );




      /* User[] users = [SELECT Id FROM User];
      User u1 = users[0];

      //  Question[] ques = [SELECT Id FROM Question];  
       //System.debug('ques --->'+ques );    
 //   Question quest = ques[0];       
 //   BadgeVilleWebServiceCallout bv = new BadgeVilleWebServiceCallout();
 //   bv.badgvilleReceiveBestAnswer(quest.Id);

 Id questId ;
   Test.startTest();  
   System.RunAs(u1)
        {            
            Question question = new Question();
            question.Title = 'Test';
            question.Body = 'Test';
            question.CommunityId = '09a50000000PNNr';//GlobalFunctions.communityId;
            insert question;  
            System.debug('question-->'+question);              
            questId = question.Id;   
            System.debug('questId --->'+questId );  

            Reply reply1 = new Reply();                
            reply1.Body =  'reply no 1 ques 1';
            reply1.QuestionId = question.Id;                 
            System.debug('reply1--->'+reply1);        
            insert reply1;
        }


      //  BadgeVilleWebServiceCallout bv = new BadgeVilleWebServiceCallout();
     //   bv.badgvilleReceiveBestAnswer(questId);   
        Test.stopTest();    


    }

我们正试图用这两种测试方法来实现这一点。但我们无法做到这一点。任何人都不知道该怎么做,或者我哪里做错了???

Salesforce不允许您测试外部Web服务

在这里,你有一个如何去做的想法

这是你的一本书


我希望这对您有所帮助。

任何人都可以帮助您,您需要解释您在哪条线路上遇到了什么错误。另外,请解释您的测试代码与生产代码之间的关系。我认为您需要告诉我们问题所在。。行和错误描述可以帮助我们为您提供建议。。现在我们不可能给你一个解决方案,因为我们没有得到任何错误,我们想为我们的apex方法运行一个测试方法。。我们正在为此尝试不同的方法,但这两种方法对我们都不起作用。。那么,任何投标商都可以建议hw为此创建一种测试方法吗。。???