问题描述:

I wonder, visual studio generates test classes with TestContext member as well as instance of it is passed to ClassInitialize method. But really, do you use this class? If so, what are the good examples where it's convenient/required to use it?

I have been writing tests for a while and never actually felt I needed to use TestContext. What about you?

网友答案:

TestContext is normally used to provide an additional context, like required path information, web services, the Page object or some means of data access.

In my opinion, if a test needs this, we're not talking about unit tests at all. So if you don't find a reason to use TestContext in your unit tests, you're doing just fine I suppose.

When it comes to integration tests, this can come in very handy though.

网友答案:

Well, for one I use it to obtain the locations of the test input/output directories and load/save files needed or generated by tests. Also to print messages to the test results, among other things.

I suppose it's possible to write unit tests without using the context at all, but I've never encountered that situation in a non-trivial testing scenario.

相关阅读:
Top