久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

為什么我們需要模擬框架?

Why do we need mocking frameworks?(為什么我們需要模擬框架?)
本文介紹了為什么我們需要模擬框架?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號..

我使用過編寫了 NUnit 測試的代碼.但是,我從未使用過模擬框架.這些是什么?我了解依賴注入以及它如何幫助提高可測試性.我的意思是在單元測試時(shí)可以模擬所有依賴項(xiàng).但是,那為什么我們需要模擬框架呢?我們不能簡單地創(chuàng)建模擬對象并提供依賴項(xiàng).我在這里錯(cuò)過了什么嗎?謝謝.

I have worked with code which had NUnit test written. But, I have never worked with mocking frameworks. What are they? I understand dependency injection and how it helps to improve the testability. I mean all dependencies can be mocked while unit testing. But, then why do we need mocking frameworks? Can't we simply create mock objects and provide dependencies. Am I missing something here? Thanks.

推薦答案

  • 它使模擬更容易
  • 他們通常讓你表達(dá)可測試提到的斷言對象之間的交互.
  • 這里有一個(gè)例子:

    var extension = MockRepository
        .GenerateMock<IContextExtension<StandardContext>>();
      var ctx = new StandardContext();
      ctx.AddExtension(extension);
      extension.AssertWasCalled(
        e=>e.Attach(null), 
        o=>o.Constraints(Is.Equal(ctx)));
    

    你可以看到我明確地測試了 IContextExtension 的 Attach 方法被調(diào)用并且輸入?yún)?shù)是上下文對象.如果沒有發(fā)生,我的測試就會(huì)失敗.

    You can see that I explicitly test that the Attach method of the IContextExtension was called and that the input parameter was said context object. It would make my test fail if that did not happen.

    這篇關(guān)于為什么我們需要模擬框架?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

    【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進(jìn)行身份驗(yàn)證并跨請求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權(quán)不起作用)
ASP Core Azure Active Directory Login use roles(ASP Core Azure Active Directory 登錄使用角色)
How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何獲取守護(hù)進(jìn)程或服務(wù)器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發(fā)技
.Net Core 2.0 - Get AAD access token to use with Microsoft Graph(.Net Core 2.0 - 獲取 AAD 訪問令牌以與 Microsoft Graph 一起使用)
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調(diào)用時(shí) Azure KeyVault Active Directory AcquireTokenAsync 超時(shí))
主站蜘蛛池模板: 日日碰狠狠躁久久躁婷婷 | 久久com | 亚洲社区在线 | 国产精品一卡 | 久久久久久999 | 黄网站免费在线看 | 日本视频在线播放 | 欧美一区在线看 | 在线精品亚洲欧美日韩国产 | 成人二区 | 日韩欧美一区二区在线播放 | 欧美一级www片免费观看 | 国产成人一区二区三区久久久 | 日韩中文字幕在线观看 | 亚州精品天堂中文字幕 | www.玖玖玖| 国产成人99久久亚洲综合精品 | av一级| 国产在线精品一区二区三区 | 色综合天天综合网国产成人网 | 亚洲国产精品视频一区 | 久久久久国产成人精品亚洲午夜 | 视频二区| 国产一区二区中文字幕 | 久久极品 | 免费同性女女aaa免费网站 | 国产精品夜夜春夜夜爽久久电影 | 精品成人av | 久草影视在线 | 免费亚洲视频 | 亚洲自拍一区在线观看 | 青草视频在线 | 成人深夜福利在线观看 | 卡通动漫第一页 | a在线视频观看 | 欧美一级在线观看 | 欧美国产日韩在线观看 | а天堂中文最新一区二区三区 | 天天干视频 | 亚洲精品久久久一区二区三区 | 正在播放国产精品 |