开发者

TestContext in Visual Studio - What does it do?

Test classes generated by Visual Studio usually have a TestContext property, as follows:

private TestContext testContextInstance;

public TestContext TestContext {
    get {
        return testContextInstance;
    }
    set {
        testContextInstance = value;
    }
}

What MSDN had to say about this wasn't particularly useful and got me no where. I haven't been able to find any examples of the usage of TestContext so far, as in read开发者_开发知识库ing from and writing to it. From the MSDN page, I understand that you'd set the DataContext as the path to your web service or access to data bases. But what if I'm trying to unit test a stand-alone desktop application, which doesn't use a database? What might I use the TestContext for?

Would someone please be able to break this down for me? (I'm using VS2010).


It is simply a way for the test runner to provide you with context information about your running tests. The MSDN page lists some use cases quite well.

Remember, you don't have to use it, but it is provided because some use cases for the unit test system needs it. In fact, in the purest meaning of "unit test", the tests should never need to know about the context - but that is another discussion.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜