Questions tagged [ocmockito]

OCMockito is an Objective-C implementation of Mockito, supporting creation, verification and stubbing of mock objects.

Key differences from other mocking frameworks:

  • Mock objects are always "nice," recording their calls instead of throwing exceptions about unspecified invocations. This makes tests less fragile.
  • No expect-run-verify, making tests more readable. Mock objects record their calls, then you verify the methods you want.
  • Verification failures are reported as unit test failures, identifying specific lines instead of throwing exceptions. This makes it easier to identify failures. (It also keeps the pre-iOS 5 Simulator from crashing.)
70 questions
1
vote
2 answers

Using OCMockito to mock methods that are void

In using OCMockito, the below works great: DSAPIManager *mockAPIManager = mock([DSAPIManager class]); [given([mockAPIManager initWithBaseURL:[mockAPIManager baseURL]]) willReturn:[DSAPIManager sharedAPIManager]]; However when I try the same thing…
Andrew Lauer Barinov
  • 5,694
  • 10
  • 59
  • 83
1
vote
0 answers

How to unit test removeObserver in dealloc

I am trying to write a failing test that would verify removeObserver is called when an object is dealloc'ed however, do to the fact that the object is no longer around, how do I determine this functionality? Am I going about testing this…
Merlin910
  • 45
  • 4
1
vote
1 answer

Feature tests with KIF: beforeEach is called after my view controller is loaded?

i have got simple (i guess) question. I want to make a feature test in my app with Specta and KIF. The problem is that i am setting dependency in viewDidLoad method of my View Controller, and in beforeEach method of my spec i'm injecting fake…
Konrad Szczęśniak
  • 1,960
  • 1
  • 14
  • 13
1
vote
1 answer

How to verify method was called

I want to test a certain method was called in response to an NSNotification being received i've tried this: _sut = mock([EAMainScreenViewController class]); [_sut view]; [[NSNotificationCenter…
Lena Bru
  • 13,521
  • 11
  • 61
  • 126
1
vote
0 answers

OCMockito XCTest does not refresh tests when changes are made and tested

I'm running into an issue where my iOS unit tests correctly execute the first time I run them on the device, but refuse to acknowledge any changes made after the initial run on either the device or simulator. If I uninstall the app and clean the…
Alex Stone
  • 46,408
  • 55
  • 231
  • 407
1
vote
1 answer

use OCMockito to test category class method

I have a UIColor category that has a class method +(UIColor *)appropriateTextColorForBackground:(UIColor *)background { //...get brightness value if (brightness > 127.5f) return [UIColor blackColor]; else return [UIColor…
1
vote
1 answer

Best way to test storyboards with OCMockito

I'm trying to test an application based on storyboards. The scenario is a Navigation Controller with a View Controller inside. The test is that performing a segue sets a view controller as destination controller (push segue). I'm using OCMockito and…
Juan Herrero Diaz
  • 833
  • 1
  • 7
  • 17
1
vote
2 answers

How to stub a method that returns void

I hope my question is not too basic, as I am new to both obj-c and OCMockito! I have a void method that I want to stub, so that it does not perform its actions when running a test. My Method: -(void)myVoidMethod { .. } I would like to stub it in…
edoDev
  • 551
  • 1
  • 4
  • 20
1
vote
0 answers

EXC_BAD_ACCESS while running OCUnit tests in Xcode

I got stuck with issue. I have OCUnit tests. I can run them successfully in iOS 7 simulator but I get EXC_BAD_ACCESS on iOS 6 simulator. Here is screenshot form Xcode: I'm using OCMockito and OCHamcrest. Do you have any idea what was the cause? I'm…
Eugen Martynov
  • 19,888
  • 10
  • 61
  • 114
1
vote
1 answer

How to stub multiple method calls in OCMockito

I am trying to unit test a method that calls the same method on a mocked object multiple times. In Java, using Mockito, I could provide multiple results to return from the method: when(mock.someMethod()).thenReturn(1,1,0); I would like to do the…
1
vote
1 answer

How do I use OCMockito to verify behaviours on a readonly property?

I'm using MVVM with ReactiveCocoa, and OCMockito for testing. Suppose I have a ViewController A and ViewController B. A needs to perform a segue to B. I want to verify that when this happens, A passes the necessary data (the 'model') along to B via…
fatuhoku
  • 4,815
  • 3
  • 30
  • 70
1
vote
1 answer

How can I verify method calls to an NSURLProtocol mock using OCMock or OCMockito?

I would like to test a method which makes a GET request. Here's a contrived example: - (void)GET:(NSString *)URLString; Rather than worry about the implementation details of this method (e.g. mocking, setting expectations, and then verifying a…
Paul Young
  • 1,489
  • 1
  • 15
  • 34
1
vote
2 answers

Questions about OCMockito setup with Cocoapods

I'm having troubles setting up OCMockito (and OCHamcrest) with Cocoapods on Xcode 5. This is my Podfile: platform :ios, '5.0' pod 'RestKit', '~> 0.20.0' pod 'OCMockito', '~> 1.0.0' link_with ['WeatherApp', 'WeatherAppTests'] When I try to follow…
UnsafePointer
  • 726
  • 6
  • 25
1
vote
2 answers

Verifying method calls in Objective-C with primitive array/pointer arguments

I have two methods in a class I'm testing: - (NSUInteger)sendBuffer:(uint8_t *)buffer length:(NSUInteger)length; - (BOOL)sendFormattedCommandForAddress:(uint8_t)address withData:(uint8_t)data …
GarlicFries
  • 8,095
  • 5
  • 36
  • 53
1
vote
1 answer

Custom OCHamcrest matcher for OCMockito mock verfication

I am using OCHamcrest and OCMockito for unit testing an iOS project. I'm working my way toward understanding using custom matchers in a mock verification of a method expectation that takes parameters. In particular, I want to verify one of the…
GarlicFries
  • 8,095
  • 5
  • 36
  • 53