Swift Mock Generator for AppCode

Compatible with AppCode
Oct 13, 2018
1 888
Automatically generate your mocks in one action.
  • Generates spies, stubs, dummies and partial spies.
  • Generates test double conforming to one or many protocols.
  • Generates test double conforming to a class.
  • Captures invocation status of methods.
  • Captures invocation status of properties.
  • Records multiple invocations of methods.
  • Records multiple invocations of properties.
  • Captures invoked method parameters.
  • Records multiple invocations of method parameters.
  • Supports multiple properties in the same declaration.
  • Stubs values for your mocks to return.
  • Stubs a default value for return values where possible.
  • Automatically calls closure parameters with stubbed values.
  • Generates convenience initializers requiring no parameters.
  • Supports initializers with arguments.
  • Supports failable initializers.
  • Supports required initializers.
  • Stub an error for your mock method to throw.
  • Supports throwing initializers.
  • Supports throwing closures.
  • Generates generic mocks from protocols with associated types.
  • Captures invoked generic parameters.
  • Captures invoked generic return values.
  • Avoids naming clashes from overloaded methods.
  • Supports parameter type-annotation attributes and `inout`.
  • Respects the mock scope and generates `public` and `open` methods and properties.
  • Generate mock inheriting from items in 3rd party frameworks.
Before:
class DataStoreSpy: DataStore {
  
}
      
After:
class DataStoreSpy: DataStore {

    var invokedSave = false
    var invokedSaveCount = 0
    var invokedSaveParameters: (data: Data, file: URL)?
    var invokedSaveParametersList = [(data: Data, file: URL)]()
    var stubbedSaveError: Error?
    var stubbedSaveResult: Bool! = false

    func save(_ data: Data, to file: URL) throws -> Bool {
        invokedSave = true
        invokedSaveCount += 1
        invokedSaveParameters = (data, file)
        invokedSaveParametersList.append((data, file))
        if let error = stubbedSaveError {
            throw error
        }
        return stubbedSaveResult
    }
}
      

Download plugin

Recent change notes

  • Can now generate a 'partial spy'. A partial spy offers the option to forward invocations to the original implementation. Only works for test doubles which inherit from a class.
  • Dummies now generate a fatal error when a default value cannot be derived since dummies are only really meant as placeholders.
  • Tuple argument labels are preserved and accessible when using the invoked parameter properties.
  • Supports AppCode 2018.2.4