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.
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.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.