gpt4 book ai didi

.net - 模拟静态类

转载 作者:行者123 更新时间:2023-12-04 10:45:50 25 4
gpt4 key购买 nike

我有一个静态类,它包装了 winspool 中的一些 native 方法:

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

我想模拟它们进行单元测试,但找不到用于此的模式。 (每个人都避免使用静态类吗?)

最佳答案

是的,静态类一般是frowned upon in the field of unit testing and mocking . AFAIK 没有开源模拟框架(例如 Rhino Mocks )支持静态类模拟

如果你绝对肯定要mock静态类,那恐怕你必须去Typemock ,这不是免费的。

关于.net - 模拟静态类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1823739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com