Skip to content

Function inside function #506

Open
Open

Description

@JeanPSF

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.

Activity

  1. liamappelbe commented on Aug 18, 2022

    @liamappelbe
    Contributor

    @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?

  2. JeanPSF commented on Aug 25, 2022

    @JeanPSF
    Author

    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,
          );
        });
      });
     
    
  3. liamappelbe commented on Aug 25, 2022

    @liamappelbe
    Contributor

    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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions