SDWebImageMockPlugin makes possible the creation of snapshot testing with views using SDWebImage to configure images

Overview

SDWebImageMockPlugin

Version License Platform CI

SDWebImageMockPlugin makes possible the creation of snapshot testing with views using SDWebImage to configure images.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Getting Started

This modules provides a ImageCacheMocker which allow you to mock all images requested by SDWebImage. To enable its mocking capabilities call its method setupSDWebImageMocking(), after that all requests from SDWebImage will use this cache instance.

class Tests: XCTestCase {

    var imageMocker = ImageCacheMocker()

    override func setUp() {
        super.setUp()
        imageMocker.setupSDWebImageMocking()
    }
    
    // Your snapshot tests here
}

Once the mocker in place the image configured by SDWebImage will depend on the url format. Here the list of the default behaviors:

  • size://1920x1080 will provide an image with a width of 1920pt and an height of 1080pt
  • ratio://3:2 will provide an image with a ratio of 3/2 and a constant height of 500pt
  • bundle://main/mySampleImage will provide the image named mySampleImage from Bundle.main (by default main is the only identifier configured in ImageCacheMocker)

Any other urls will return a default image.

Extension on URL are provided to construct those default urls:

bundle://testBundle/sampleImage1">
URL.imageMock(forWidth: 500, height: 100) // -> size://500x100
URL.imageMock(withRatio: Double(16) / Double(9)) // -> ratio://1.7777777777777777:1 (equivalent to ratio://16:9)
URL.imageMock(named: "sampleImage1", inBundleID: "testBundle") // -> bundle://testBundle/sampleImage1

Those behaviors are customizable by registering a custom image provider using ImageCacheMocker.registerProvider(:).

You can find the example Tests here: Tests.swift, and the snapshots for those tests:

testViewController.1.png testMultipleImagesViewController.1.png testConfiguredMultipleImagesViewController.1.png

Installation

Cocoapods

SDWebImageMockPlugin is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SDWebImageMockPlugin'

Swift Package Manager

SDWebImageMockPlugin can be installed as a Swift Package with Xcode 11 or higher. To install it, add a package using Xcode or a dependency to your Package.swift file:

.package(url: "https://github.com/faberNovel/SDWebImageMockPlugin")

Credits

SDWebImageMockPlugin is owned and maintained by Fabernovel. You can follow us on Twitter at @Fabernovel.

License

SDWebImageMockPlugin is available under the MIT license. See the LICENSE file for more info.

You might also like...
TRex 🦖 TRex makes OCR easy and accessible on a Mac
TRex 🦖 TRex makes OCR easy and accessible on a Mac

TRex 🦖 TRex makes OCR easy and accessible on a Mac. But what is OCR anyway? Imagine you have a PDF file or a Web page where you can't select the text

A library that makes defines your style sheet like a breeze.

Atelier A library that makes defines your style sheet like a breeze. Requirements iOS 13.0+ Xcode 12.0+ Swift 5.3+ Installation You can add Atelier to

ColorKit makes it easy to find the dominant colors of an image
ColorKit makes it easy to find the dominant colors of an image

ColorKit ColorKit is your companion to work with colors on iOS. Features Installation Sample Project Contributing License Features Dominant Colors Col

STDevRxExt contains some extension functions for RxSwift and RxCocoa which makes our live easy.

STDevRxExt Example To run the Example.playground, clone the repo, and run pod install from the Example directory first. Requirements iOS 9.0+ tvOS 9.0

XcodeColorSense - An Xcode plugin that makes working with color easier.
XcodeColorSense - An Xcode plugin that makes working with color easier.

XcodeColorSense An Xcode plugin that makes working with color easier. Inspired by ColorSense-for-Xcode with extra care for Hex color Features Show col

Agrume - 🍋 An iOS image viewer written in Swift with support for multiple images.
Agrume - 🍋 An iOS image viewer written in Swift with support for multiple images.

Agrume An iOS image viewer written in Swift with support for multiple images. Requirements Swift 5.0 iOS 9.0+ Xcode 10.2+ Installation Use Swift Packa

APNGKit is a high performance framework for loading and displaying APNG images in iOS and macOS.
APNGKit is a high performance framework for loading and displaying APNG images in iOS and macOS.

APNGKit is a high performance framework for loading and displaying APNG images in iOS and macOS. It's built on top of a modified version of libpng wit

A lightweight generic cache for iOS written in Swift with extra love for images.
A lightweight generic cache for iOS written in Swift with extra love for images.

Haneke is a lightweight generic cache for iOS and tvOS written in Swift 4. It's designed to be super-simple to use. Here's how you would initalize a J

Kingfisher is a powerful, pure-Swift library for downloading and caching images from the web
Kingfisher is a powerful, pure-Swift library for downloading and caching images from the web

Kingfisher is a powerful, pure-Swift library for downloading and caching images from the web. It provides you a chance to use a pure-Swift way to work

Releases(v0.1.0)
  • v0.1.0(Feb 28, 2022)

    Created

    Classes

    • ImageCacheMocker

    Structures

    • ImageProvider

    Extensions

    • ImageProvider.sizeImageProvider
    • ImageProvider.ratioImageProvider
    • ImageProvider.bundleImageProvider(bundlesWithIdentifiers:)

    External extensions

    • URL.imageMock(forWidth: Double, height: Double)
    • URL.imageMock(withRatio ratio: Double)
    • URL.imageMock(named imageName: String, inBundleID bundleID: String)
    Source code(tar.gz)
    Source code(zip)
Owner
FABERNOVEL
FABERNOVEL
SwiftUI Image loading and Animation framework powered by SDWebImage

SDWebImageSwiftUI What's for SDWebImageSwiftUI is a SwiftUI image loading framework, which based on SDWebImage. It brings all your favorite features f

null 1.6k Jan 6, 2023
EbImagesSwiftUI - SDWebImageSwiftUI - a SwiftUI image loading framework, which based on SDWebImage

SDWebImageSwiftUI What's for SDWebImageSwiftUI is a SwiftUI image loading framew

An Tran 1 Jan 6, 2022
Makes dealing with images buttery smooth.

ImageButter Image viewer for iOS that supports WebP. What is WebP? Find out more here. You can find more about why we created this here. Features Anim

Dollar Shave Club 397 Nov 19, 2022
iOS Framework that makes it easy to preview images on any UIImageView.

AZImagePreview iOS Framework that makes it easy to preview images on any UIImageView. Screenshots Installation: Cocoa Pods: pod 'AZImagePreview' Swift

Antonio Zaitoun 25 Dec 11, 2022
A Swift/SwiftUI utility for caching and displaying images in SwiftUI Views

A Swift/SwiftUI utility for caching and displaying images asynchronously. Built with Swift 5.5 and works with async/await.

王雪铮 Xuezheng Wang 1 May 5, 2022
A simple macOS app to read code from images, written purely in Swift using Vision Framework.

CodeReader A simple macOS app to read code from images, written purely in Swift using Vision Framework. Usage Drag an image Click the convert button R

Md Ibrahim Hassan 44 Nov 20, 2022
A view that takes a set of images, make transition from one to another by using flipping effects.

CDFlipView A view that takes a set of images, make transition from one to another by using flipping effects. Demo Live Demo: https://appetize.io/app/w

Jianbin LIN 99 Aug 27, 2021
Using remote images in an application is more or less a requirement these days.

Imaginary Table of Contents Description Usage Basic Advanced Configuration ImageFetcher Installation Description Using remote images in an application

HyperRedink 597 Nov 8, 2022
Style Art library process images using COREML with a set of pre trained machine learning models and convert them to Art style.

StyleArt Style Art is a library that process images using COREML with a set of pre trained machine learning models and convert them to Art style. Prev

iLeaf Solutions Pvt. Ltd. 222 Dec 17, 2022
High Quality Image ScrollView using cropped tiled images.

THTiledImageView Feature ?? THTiledImageView fully support UIScrollView. You can subclass it and use it. ?? Support Async Image Downloading & Caching.

null 28 Oct 28, 2022