3
我想知道什麼是編寫Microsoft Visual Studio單元測試Assert類的自定義擴展方法的最佳方法。爲VS UT Assert類創建自定義擴展方法的最佳方式是什麼?
我想知道什麼是編寫Microsoft Visual Studio單元測試Assert類的自定義擴展方法的最佳方法。爲VS UT Assert類創建自定義擴展方法的最佳方式是什麼?
如果您指的是這個Assert類,那麼您不能添加擴展方法。擴展方法只能應用於對象實例。由於這個類是靜態的,它永遠不會被實例化。
你可以添加自己的自定義斷言類型的類像這樣雖然:
public static class MyAssert {
public static void AreEqual(object expected, object actual) {
// TODO: throw if not equal
}
}
我寫我自己的可擴展的包裝上斷言的前頭網站。源代碼可以在這裏找到:https://github.com/bbraithwaite/MSTestExtensions –