-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mocking an subclass of ManagedObject #8
Comments
Hi there. Can you be more specific and come with a use case where you would want to mock a subclass of ManagedObject. |
Hello there. I've tried to override a property and override the getter and setter as describe in the example below.
My attempt was to stub the property in my testing class as follow:
But stubbing this way was not always successful. I sometimes observed weird behaviours like Xcode telling me that the property has been called or not called once as if I was doing a check like a I am wondering if the Mockit framework allows to stub properties or am I doing it the wrong way ? Thanks for you time. |
Thanks for contacting mate. I m a bit in a rush. Will get back to you
tomorrow. Thanks.
On Thu, Oct 18, 2018 at 10:15 PM JC-Nicolas ***@***.***> wrote:
Hello there.
Coming from OCMock I am now using Mockit and I'm enjoying it.
However, there is something about stubbing properties that I do not seem
to understand.
I've tried to override a property and override the getter and setter as
describe in the example below.
class MCKMyCustomView: MyCustomView, Mock {
let callHandler: CallHandler
init(testCase: XCTestCase, frame: CGRect) {
self.callHandler = CallHandlerImpl(withTestCase: testCase)
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func instanceType() -> MCKMyCustomView {
return self
}
override open var infosLabel: UILabel? {
get {
return self.callHandler.accept(nil, ofFunction: #function, atFile: #file, inLine: #line, withArgs: nil) as? UILabel
}
set {
self.callHandler.accept(nil, ofFunction: #function, atFile: #file, inLine: #line, withArgs: nil)
}
}
}
My attempt was to stub the property in my testing class as follow:
// Mock
let mck_view = MCKMyCustomView(testCase: self, frame: frame)
// Stub
mck_view.when().call(withReturnValue: mck_view.infosLabel).thenReturn(nil)
But stubbing this way was not always successful. I sometimes observed
weird behaviours like Xcode telling me that the property has been called or
not called once as if I was doing a check like a Once() or Never() on a
method. I did observed property behaving as it was not stubbed.
I am wondering if the Mockit framework allows to stub properties or am I
doing it the wrong way ?
Thanks for you time.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#8 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AKNcGHwujJ8iz2TU6Wj9iPnvH7iC8JUwks5umKkGgaJpZM4Lx51i>
.
--
Regards,
Syed Sabir Salman-Al-Musawi
Software Engineer
Dynamic Solution Innovators, http://www.dsinnovators.com/
Phone: +8801680464463
Github: *https://github.com/sabirvirtuoso
<https://github.com/sabirvirtuoso>*
|
Hello sabirvirtuoso, did you find the time to look at the issue ? |
Hi, stubbing properties, more specifically getters and setter seems to be out of scope of the current implementation. Please feel free to add this feature and send me a PR. Thanks |
Is it possible? I'm just starting out and am receiving some build errors that I don't quite understand.
The text was updated successfully, but these errors were encountered: