Skip to main content

While doing module Unit Testing on the Lightning Platform > Use Mocks and Stub Objects

 

Trying to complete challenge I get the error message :

 

Challenge not yet complete in Creative Fox Playground

 

The test methods in 'ExternalSearch_Tests' are not providing 100% test coverage for the 'ExternalSearch' class.

 

I asked for assistance from the trailhead help and support as always and was told to post my issue here.

Please advice what I need to do.

8 risposte
  1. 28 set 2020, 15:50

    Hi Haresh,

     

    It seems you have modified the existing test class method given in the unit. But you have to add a new test method to existing class and run the test for both methods which covers 100% code coverage. I have modified the test class as given in the example and added another method in your org and now your code looks like below:

     

    @isTest

     

    private class ExternalSearch_Tests {

     

      @isTest static void test_method_one() {

     

        HttpMockFactory mock = new HttpMockFactory(200, 'OK', 'I found it!', new Map<String,String>());

     

        Test.setMock(HttpCalloutMock.class, mock);

     

        String result;

     

        Test.startTest();

     

          result = ExternalSearch.googleIt('epic search');

     

        Test.stopTest();

     

        system.assertEquals('I found it!', result);

     

      }

     

    @isTest static void test_method_two() {

     

        HttpMockFactory mock = new HttpMockFactory(500, 'OK', 'I found it!', new Map<String,String>());

     

        Test.setMock(HttpCalloutMock.class, mock);

     

        String result;

     

        Test.startTest();

     

          result = ExternalSearch.googleIt('epic search');

     

        Test.stopTest();

     

        system.assertEquals('I found it!', result);

     

      }

     

    }

     

    Please run the test (select 2 methods)and you can see the code coverage as 100%.

     

    Please mark this as Best Answer and close this thread if it helps you. So that other Trailblazers can use this solution if needed.

     

    Thanks,

     

    Ravindra