Swift Mock Generator for AppCode

Compatible with AppCode
May 20, 2018
1 546
Automatically generate your mocks in one action.
  • Generates mock conforming to one or many protocols.
  • Generates mock 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 MockDataStore: DataStore {
  
}
      
After:
class MockDataStore: 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

  • 'Generate mock' has been renamed to 'Generate spy'.
  • Can now generate a simpler test double when only stubbing is required. Choose 'Generate stub'.
  • Can now generate the simplest possible test double; a dummy. Choose 'Generate dummy'.