tools icon indicating copy to clipboard operation
tools copied to clipboard

Function inside function

Open JeanPSF opened this issue 3 years ago • 3 comments

Is there a way for the coverage to detect already tested functions inside other functions?

If I put the function call directly into the return, then, the return becomes also not covered.

JeanPSF avatar Aug 16 '22 15:08 JeanPSF

@JeanPSF I can't reproduce this based on just these small code snippets. Can you give me more context, or better yet, post a minimal repro program?

liamappelbe avatar Aug 18 '22 17:08 liamappelbe

The tests I am running are these (they are passing).


  group('On retrieving User Preferences tests => ', () {
    UserPreferences? failUserPreferencesMockResult;
    UserPreferences? successUserPreferencesResult;

    setUpAll(() async {
      safePrint('running user pref setUpAll!');
      failUserPreferencesMockResult = await userAPI
          .getUserPreferences()
          .then(
            (result) => userApiMock.onRetrieveUserPreferencesError,
          )
          .onError(
            (error, stackTrace) => userApiMock.onRetrieveUserPreferencesError,
          );

      successUserPreferencesResult = await userAPI
          .getUserPreferences()
          .then(
            (result) => userApiMock.onRetrieveUserPreferencesSuccess,
          )
          .onError(
            (error, stackTrace) => userApiMock.onRetrieveUserPreferencesSuccess,
          );
    });

    test('Error.', () {
      expect(failUserPreferencesMockResult, null);
    });
    test('Success.', () {
      expect(
        successUserPreferencesResult,
        isA<UserPreferences>(),
      );
    });
  });


  group('Serializers tests => ', () {
    test('UserPreferences cast => OK.', () {
      expect(
        userAPI.userPreferencesJsonToClass(
          UserPreferencesMock().userPreferencesJson,
        ),
        UserPreferencesMock().userPreference,
      );
    });
  });
 

JeanPSF avatar Aug 25 '22 14:08 JeanPSF

What about the code under test? What is userAPI? Where are the UserPreferences and UserPreferencesMock defined?

What Http class are you using? In your original post, the code that isn't covered comes after awaiting the result of what looks like a network request. How are you mocking this for testing? Are you sure that missed line is actually being hit?

liamappelbe avatar Aug 25 '22 22:08 liamappelbe