1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Error generating Mocks with @GenerateNiceMocks annotation flutter dart

Discussão em 'Mobile' iniciado por Stack, Outubro 16, 2024 às 08:32.

  1. Stack

    Stack Membro Participativo

    I am trying to Mock a class with @GenerateNiceMocks, when I setup @GenerateNiceMocks and tried to build the generated files I encountered following problem.

    Invalid @GenerateMocks annotation: Mockito cannot generate a valid mock
    class which implements 'CLASS TO MOCK' for the following reasons:

    The property accessor 'CLASS.VARIABLE=' features a private parameter type, '_ANOTHERCLASS', and cannot be stubbed.
    Try generating this mock with a MockSpec with 'unsupportedMembers' or a dummy generator (see
    https://pub.dev/documentation/mockito/latest/annotations/MockSpec-class.html).


    Following is replica of my code:

    class CLASSTOMOCK {
    late final _ANOTHERCLASS classVariable;

    CLASSTOMOCK(){
    classVariable = _ANOTHERCLASS();
    }
    }


    I have tried with all the options of Mocking like @GenerateMocks, @GenerateNiceMocks and creating a new class by extending Mock and implementing CLASSTOMOCK. But no luck.

    I am also using unsupportedMembers option in @GenerateNiceMocks but it's not working properly.

    Thank you in advance for helping me.

    Continue reading...

Compartilhe esta Página