I am using Rhino.Mocks
to mock objects for unit testing my .net application. I want to mock a static class. If someone has idea of how to do this, please suggest.
Asked
Active
Viewed 5,361 times
0

davmos
- 9,324
- 4
- 40
- 43

munish gautam
- 91
- 2
- 9
-
static methods and classes are very difficult to test! – c0deNinja Dec 07 '11 at 07:57
-
2this has also been covered: http://stackoverflow.com/questions/540239/mocking-static-methods-using-rhino-mocks – c0deNinja Dec 07 '11 at 07:59
-
mocks are for creating instances that conform to some abstraction without the real implementation. this is not something they were ever intended to do. i get that you can do things like this with typemock and such, but it's getting away from the intent and is indicative of bigger problems in design. if a static method is doing something with external dependencies such that you'd care to mock it, it probably shouldn't be a static method. – Dave Rael Dec 10 '11 at 13:50
1 Answers
3
Short answer : you can't.
You can wrap the static up in a facade object and then mock that which will probably acheive wwhat you want.

Community
- 1
- 1

Dave Walker
- 3,498
- 1
- 24
- 25