Unit testing FFImageLoading and calling CachedImageRenderer.Init?

LeloLelo Member ✭✭✭

I am trying to create unit test that calls methods that are dependent of FFImageLoading.Forms.CachedImage
. I get this exception:
System.Exception: Please call CachedImageRenderer.Init method in a platform specific project to use FFImageLoading!
How can I call this method from a test project? Will I have to create platform specific code snippet that calls init? Or is there any other way around it?

Answers

  • ElandaloussiishrakElandaloussiishrak USMember ✭✭

    Add
    CachedImageRenderer.Init(); in "OnCreate" function in MainActivity.cs class of your android project
    and in FinishedLaunching function in AppDelegate class of your iOS project

  • LeloLelo Member ✭✭✭

    @Elandaloussiishrak said:
    Add
    CachedImageRenderer.Init(); in "OnCreate" function in MainActivity.cs class of your android project
    and in FinishedLaunching function in AppDelegate class of your iOS project

    I have already done that. But I wonder how to call methods depending on CacheImage from MsTest or xUnit test project?

  • nemscatnemscat Member

    @Lelo I had the same issue and after searching through lots of code in their official github page i found something that helped.

    Add this to your unit test "Setup";
    FFImageLoading.ImageService.EnableMockImageService = true;

    Example;
    [BeforeScenario()]
    public void BeforeScenarioSetup()
    {
    base.Setup();
    MockForms.Init("Android");
    ** FFImageLoading.ImageService.EnableMockImageService = true; **
    }

    Hope this helps

Sign In or Register to comment.