永发信息网

C#或者VB中怎么判断dll中获得的类和方法属于单元测试的类TestClass和方法TestMethod?

答案:2  悬赏:20  手机版
解决时间 2021-03-18 07:03
  • 提问者网友:战皆罪
  • 2021-03-17 17:38
正在做一个小工具,要通过VB工程中单元测试编译生成的Dll来确定单元测试中测试类的数量和测试方法的数量
最佳答案
  • 五星知识达人网友:山君与见山
  • 2021-03-17 18:57
[CodedUITest]
    public class CodedUITest1
    {
        public CodedUITest1()
        {
            Type t = typeof(CodedUITest1);
            //关键是GetCustomAttributes
            //根据输出的字符串,你就可以用一些办法来判断了
            foreach (object o in t.GetCustomAttributes(true))
                Debug.WriteLine(o);
            MethodInfo mi = t.GetMethod("CodedUITestMethod1");

            foreach (object o in mi.GetCustomAttributes(true))
                Debug.WriteLine(o);
        }

        [TestMethod]
        public void CodedUITestMethod1()
        {

        }
    }
全部回答
  • 1楼网友:低音帝王
  • 2021-03-17 19:23
例子: using system; using system.runtime.interopservices; namespace anytao.net { class mainclass { [dllimport("user32.dll")] public static extern int messagebox(int hparent, string msg, string caption, int type); static int main() { return messagebox(0, "how to use attribute in .net", "anytao_net", 0); } } } 你的错误有两个可能, 一是,vb生成的dll组件有问题,所以调用失败 二是,已经成功生成dll:checkname.dll [dllimport("工程1.dll")] 调用的组件书写不正确,应该是[dllimport("checkname.dll")]
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯