Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8697865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:37:05+00:00 2026-06-13T01:37:05+00:00

Im a beginner to OCMock and I need to verify if a method is

  • 0

Im a beginner to OCMock and I need to verify if a method is invoked from another class. The following is my code.

 //Creating the OCMockObject
id mockProductRequest = [OCMockObject mockForClass:[ProductRequest class]];
[[mockProductRequest expect] testProductRequest];

//Creating the object where the mock object will be invoked
ProductService *actualService = [[ProductService alloc] init];
[actualService testProductService];

[mockProductRequest verify];

-(void)testProductService{
//Method where the mock object's method is invoked
ProductRequest *request = [[ProductRequest alloc] init];
[request testProductRequest];
}

I seems to always receive a method was not invoked exception. Please help me to figure out what I’m doing wrong here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:37:06+00:00Added an answer on June 13, 2026 at 1:37 am

    You have to replace the real request inside the real ProductService. You can archiev this for example by making the request a property of the ProductService like this:

    @interface ProductService
    @property (strong) ProductRequest *request
    

    and then exchange the real ProductRequest with the mocked one like this

    - (void)testProductService {
      id mockProductRequest = [OCMockObject mockForClass:[ProductRequest class]]; 
      [[mockProductRequest expect] testProductRequest];
    
      ProductService *actualService = [[ProductService alloc] init]; 
      actualService.request = mockProductReqeust;
    
      // call some method on actualService which invokes the request
    
      [request testProductRequest];
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

another beginner problem. Why isn't the following code with an asp.net page not working?
Beginner in Android development. My code crashes. I have made a simple Java method
Level: Beginner In the following code my 'samePoint' function returns False where i am
Beginner in JS :) needs an explanation of code piece from Crockford's book ,
JS beginner here. I need help with a script to place different content in
Question : Beginner Level Code: Pure Javascript I had created a web page in
Beginner rails question: How does one return a file from a controller in rails?
Python beginner here. I am using the matplotlib library to make graphs from tab
Definitely a beginner question... basically, I want to have the same design from this
Beginner question... How different is define($a,365); from $a = 365; ? Thanks! JDelage

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.