从其他类捕获信息到testcontext [英] Capturing info to testcontext from other classes

查看:42
本文介绍了从其他类捕获信息到testcontext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建了几个没有任何测试方法的页面对象模型类。想要将测试详细信息添加到testContext而不是Console.WriteLine调用。我怎样才能进行泛型调用,而不是为每个方法传递TestContext实例,
不是codedui测试类?

Created few page object model classes, which are not having any test methods. Would like to add test details to testContext instead of Console.WriteLine calls. How can I make it generic call, instead of passing TestContext instance for each method, which is not codedui test class?

推荐答案

朋友,

>> 如何使其成为通用调用,而不是为每个方法传递TestContext实例

>> How can I make it generic call, instead of passing TestContext instance for each method

我认为如何创建 ClassInitialize 方法?  ;

I think How about creating ClassInitialize method? 

    private static TestContext msTestContext

    [ClassInitialize]
    public static void ClassInit(TestContext para)
    {
      bingTestContext = para;
    }

使用此处给出的ClassInitialize方法,您将在类中的所有测试方法之间共享一个 TestContext 实例。这意味着如果单元测试在测试上下文中存储任何内容,
或通过其WriteLine方法写入测试上下文,则单元测试不再相互隔离。

With the ClassInitialize approach given here, you will have one TestContext instance shared among all test methods in the class. This means your unit tests are no longer isolated from each other if they store anything in the test context, or write to the test context via its WriteLine method.




请如果我误解,请随时告诉我。 

Please feel free to let me know if I misunderstood. 




祝你好运, 

Best regards, 

Fletch


这篇关于从其他类捕获信息到testcontext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆