typealiased / mockingbird

A Swifty mocking framework for Swift and Objective-C.

Home Page:https://mockingbirdswift.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generator should support mocking methods from parent class

juyan opened this issue · comments

New Feature Request Checklist

Overview

It looks like generate mocks does not support parent class's methods.

Example

Swift Package "Base":

open class BaseClass {
    public func getBaseVersion() -> Int
}

Swift Package "Middle":

import Base

public class MiddleClass: BaseClass {
    public func getMiddleVersion() -> Int
}

Now run mockingbird on package Middle with the following command. Note that we have copied BaseClass.swift under the MockingbirdSupport folder.

mockingbird generate --project project.json --output-dir Tests/MiddleTests --targets Middle --support ~/Downloads/MockingbirdSupport

Note that in the generated mock file, only getMiddleVersion is mocked, but not getBaseVersion.

Expected

The generate mock should also support mocking method getBaseVersion.

This is something that’s supported, so it sounds like your Mockingbird support configuration has some issues.

  • Is BaseClass.swift in a directory that matches the module name? In your example that would be Base.
  • Does the file declaring MiddleClass explicitly import Base?
  • Do you get any diagnostic errors or warnings if you include --diagnostics all? The generator will complain if you’re inheriting from a type it doesn’t know about.

Is BaseClass.swift in a directory that matches the module name? In your example that would be Base.

Yes

Does the file declaring MiddleClass explicitly import Base?

Yes

Do you get any diagnostic errors or warnings if you include --diagnostics all? The generator will complain if you’re inheriting from a type it doesn’t know about.

No errors got.

@andrewchang-bird
Please checkout my source code here. Not sure why it is not working as expected.

Thanks for providing the repo. Since class mocks rely on subclassing and Base is defined a separate module, getBaseVersion needs to be open instead of public.