C 反射技術測試筆記

2022-03-25 12:05:10 字數 2414 閱讀 5513

反射測試筆記,主要測試的重點有

a.通過反射得到類中的『屬性』名(以前我特別想得到屬性的名稱或者變數名)

b.兩種反射的應用,乙個是通過型別反射,乙個是通過『程式集名』反射

c.呼叫反射類的方法(包括例項方法、靜態方法)

d.建立乙個反射類的新例項

1.用於反射的測試類

using system;

using system.collections.generic;

using system.linq;

using system.text;

namespace attribute.utility.testfield

public string att11

public string att12

public string att13

public void fun11()

public void fun12()

public void fun13()

public string fun14()

public string fun15()

public string fun16() }}

2. 反射的一些測試方法 

#region 方法

///

/// 顯示資訊到窗體控制項

///

///

private void showmsg(object msg)

showmsg(msg.tostring());

}///

/// 顯示資訊到窗體控制項(lsbmsg 為 winfrom 中的 listbox 控制項)

///

///

private void showmsg(string msg)

///

/// 顯示指定型別的成員資訊

///

///

private void showfield(type t)

//獲得當前型別的公共方法名

system.reflection.methodinfo methods = t.getmethods();

this.showmsg("----- getmethods() -----");

foreach (system.reflection.methodinfo f in methods)

//獲得當前型別的公共屬性名

system.reflection.propertyinfo properts = t.getproperties();

this.showmsg("----- getproperties() -----");

foreach (system.reflection.propertyinfo f in properts)

attribute.utility.testfield.fieldcls1 fcls =

new attribute.utility.testfield.fieldcls1();

//因為乙個類不僅僅包含了自定的方法,還包含了一些基類的一些方法

//這裡只是通過 linq 把自定義的方法查了出來

system.reflection.methodinfo custommethods =

methods.where(o =>

).toarray();

//呼叫反射後的方法

this.showmsg("----- invoke getmethods() -----");

object obj = t.assembly.createinstance(t.fullname);

foreach (system.reflection.methodinfo f in custommethods)

,returns = "

, f.name

, f.invoke(obj, null) //注意:obj 為反射類的例項類,如果呼叫的方法為靜態的這個引數則為 null

));}

//呼叫反射後類的例項化方方法

this.showmsg("----- execute instance method -----");

//object obj = t.assembly.createinstance(t.fullname, true);

if (obj is attribute.utility.testfield.fieldcls1)

,returns = ", cls.tostring(),cls.fun14()));

this.showmsg(string.format(",returns = ", cls.tostring(),cls.fun15()));

this.showmsg(string.format(",returns = ", cls.tostring(),cls.fun16()));}}

#endregion

黑盒測試筆記

黑盒測試又稱功能測試 在已知產品功能設計規格的基礎上進行測試,以證明每個實現了的功能是否符合要求 等價類劃分 邊界值分析 錯誤推測法 因果圖 等價類劃分 將所有可能的輸入資料,劃分為等價的部分,然後從每個部分中選取少數有代表性的資料作為測試用例。等價類可以分為有效等價類 即合理的 有意義的資料集合 ...

軟體測試筆記

qtp loadrunner 整合測試 integration testing 是在假定各個軟體單元已經通過了單元測試的前提下,檢查各個軟體單元之間的相互介面是否正確。也稱為組裝測試 聯合測試 子系統測試或部件測試 整合測試演變出了功能測試,效能測試 方法處理資料的時間,方法併發能力 整合測試的方面...

軟體測試筆記

軟體測試 黑盒測試 一 黑盒測試主要發現以下錯誤 1.是否有不正確或者遺漏的功能 2.介面是否有錯誤 3.在介面上,輸入能否正確的接收?能否輸出正確的結果 4.效能上能否滿足需求 5.是否 有初始化或終止化性的錯誤?二 1.黑盒測試的優點 從產品功能的角度測試可以最大限度的滿足客戶的需求 相同動作可...