Kevin Meredith Kevin Meredith - 1 year ago 90
C# Question

Mocking Static Methods

Recently, I've begun to use Moq to unit test. I use Moq to mock out classes that I don't need to test.

How do you typically deal with static methods?

public void foo(string filePath)
File f = StaticClass.GetFile(filePath);

How could this static method,
get mocked?

P.S. I'd appreciate any reading materials you recommend on Moq and Unit Testing.

Answer Source

Mocking frameworks like Moq or Rhinomocks can only create mock instances of objects, this means mocking static methods is not possible.

You can also search Google for more info.

Also, there's a few questions previously asked on StackOverflow here, here and here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download