Redirecting Console.Out within test Setup and Teardown

前端 未结 1 1707
你的背包
你的背包 2021-01-22 01:21

This is a follow up from Grabbing the output sent to Console.Out from within a unit test? and the referenced article in the accepted answer by Mark Seemann.

I would like

相关标签:
1条回答
  • 2021-01-22 01:32

    Are there any major drawbacks of using setup or teardown methods for this?

    Yes, although it may not be measurable.

    The way Setup and TearDown method is described here, two new disposable objects are created for every test, but they are never disposed of. They'll eventually go out of scope and be finalised when the garbage collector runs, but it may happen in a less deterministic fashion. In theory, it'll use more memory and processor instructions than if they were deterministically disposed of, but as Knuth taught us 40 years ago, we should measure instead of engaging in premature optimisations.

    My main problem with using mutable state and Implicit Setup and Teardown is that it's not thread-safe, so if you ever want to run your unit tests in parallel, you can't.

    0 讨论(0)
提交回复
热议问题