亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在C#中測試私有方法的單元

在C#中測試私有方法的單元

繁花如伊 2019-07-29 11:23:19
在C#中測試私有方法的單元Visual Studio允許通過自動生成的訪問器類對私有方法進行單元測試。我編寫了一個成功編譯的私有方法的測試,但它在運行時失敗了。一個相當小的代碼和測試版本是://in project MyProjclass TypeA{     private List<TypeB> myList = new List<TypeB>();     private class TypeB     {         public TypeB()         {         }     }     public TypeA()     {     }     private void MyFunc()     {         //processing of myList that changes state of instance     }}    //in project TestMyProj           public void MyFuncTest(){     TypeA_Accessor target = new TypeA_Accessor();     //following line is the one that throws exception     target.myList.Add(new TypeA_Accessor.TypeB());     target.MyFunc();     //check changed state of target}運行時錯誤是:Object of type System.Collections.Generic.List`1[MyProj.TypeA.TypeA_Accessor+TypeB]' cannot be converted to type 'System.Collections.Generic.List`1[MyProj.TypeA.TypeA+TypeB]'.根據intellisense - 因此我猜編譯器 - 目標是TypeA_Accessor類型。但在運行時它的類型為TypeA,因此列表添加失敗。有什么辦法可以阻止這個錯誤嗎?或者,或許更有可能的是,其他人有什么其他建議(我預測可能“不測試私有方法”和“沒有單元測試操縱對象的狀態”)。
查看完整描述

3 回答

  • 3 回答
  • 0 關注
  • 873 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號