Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mocking a Static Class

I have a static class that wraps some native methods from winspool:

public static class WinSpool
{
     [DllImport("winspool.drv")]
     public static extern int OpenPrinter(string pPrinterName, out IntPtr phPrinter, IntPtr pDefault);
     ...
     //some more methods here
}

I would like to mock them for unit testing, but couldn't find a pattern for this. (Does everyone avoid static classes?)

like image 657
moogs Avatar asked Dec 01 '09 03:12

moogs


1 Answers

Yes, static class is generally frowned upon in the field of unit testing and mocking. AFAIK no open source mocking framework ( such as Rhino Mocks) support static class mocking

If you absolutely and positively must mock static class, then I afraid that you must go for Typemock, which is not free.

like image 118
Graviton Avatar answered Sep 21 '22 08:09

Graviton