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

  • Home
  • SEARCH
  • 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 8836999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:37:10+00:00 2026-06-14T09:37:10+00:00

I am trying to mock static functions in my project. I am unable to

  • 0

I am trying to mock static functions in my project. I am unable to do this using Rhynomocks hence trying to mock static functions using Typemock.

They say it is possbile to mock static function using typemock and the same example is provided in below article

http://www.typemock.com/basic-typemock-unit-testing

however it doesn’t seem to work for me. Below is my code:

public class Class1Test
{
[Isolated(Design = DesignMode.Pragmatic)]
[Test]
public void function()
{
Isolate.Fake.StaticMethods(Members.MustSpecifyReturnValues);

        Isolate.WhenCalled(() => LoggerFactory.Add(6, 4)).WillReturn(11);

        int value = LoggerFactory.Add(5, 6);
    }


}

———————————————–LoggerFactory.cs

public class LoggerFactory
{

    public static  int Add(int intx, int inty)
    {
        return intx + inty;
    }

}

Error what I get is:

* Faking non-virtual methods is not possible in InterfaceOnly design mode. Use [Isolated(DesignMode.Pragmatic)] to fake this. Learn more here http://www.typemock.com/isolator-design-mode

Thanks in advance.

  • 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-14T09:37:11+00:00Added an answer on June 14, 2026 at 9:37 am

    Your example code looks incomplete. I just put a slightly modified reproduction together using your code and it works fine. In specific, the Isolate.Fake.StaticMethods call is missing the type you intend on mocking.

    using System;
    using NUnit.Framework;
    using TypeMock.ArrangeActAssert;
    
    namespace TypeMockDemo
    {
      public class LoggerFactory
      {
        public static int Add(int intx, int inty)
        {
          return intx + inty;
        }
      }
    
      // The question was missing the TestFixtureAttribute.
      [TestFixture]
      public class LoggerFactoryFixture
      {
        // You don't have to specify DesignMode.Pragmatic - that's the default.
        [Isolated(Design = DesignMode.Pragmatic)]
        [Test]
        public void Add_CanMockReturnValue()
        {
          // The LoggerFactory type needs to be specified here. This appeared
          // missing in the example from the question.
          Isolate.Fake.StaticMethods<LoggerFactory>(Members.MustSpecifyReturnValues);
    
          // The parameters in the Add call here are totally ignored.
          // It's best to put "dummy" values unless you are using
          // WithExactArguments.
          Isolate.WhenCalled(() => LoggerFactory.Add(0, 0)).WillReturn(11);
    
          // Note the parameters here. No WAY they add up to 11. That way
          // we know you're really getting the mock value.
          int value = LoggerFactory.Add(100, 200);
    
          // This will pass.
          Assert.AreEqual(11, value);
        }
      }
    }
    

    If you can paste that code into a project (with Typemock and NUnit references) and it doesn’t work, then you may be having troubles executing the tests properly, or you may have a misconfiguration on your machine. In either case, you will probably want to contact Typemock Support if the above code doesn’t work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to mock out a using with a file stream but
I've been trying to get to mock a method with vararg parameters using Mockito:
I have built a mock object using EasyMock, and I'm trying to have the
I'm currently trying to mock the following method using Jack. The code example is
I have this static helper function: public static DependencyObject GetParentObject(DependencyObject child) { if (child
I'm trying to mock an Excel spreadsheet using NSubstitute or other mocking framework and
I'm trying to mock an existing Web Service in another environment for testing purposes
I'm trying to mock a mapping interface IMapper : public interface IMapper<TFoo, TBar> {
I am trying to Mock an object that is being passed into another object,
I'm trying to use mock to verify that an index property has been set.

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.