c# - How can I isolate unit tests by class? -
Many of my 'unit tests' (they are actually integration tests) that use shared resources in many classes , And I want that every exam square only gets resources (for reasons of performance)
However, when I leave the resource in Here's a simple example: at least on my machine, I have read, but it does not interpret any kind of behavior to change. And I realize that I should not depend on the test order, but every test is very expensive to retrieve the resource, so I want to group them by class. How can I fix this? Is there a way to force each test to run the classroom as a unit, and is the cleaning done immediately? Although Once the sharing resource is not released, the final exam is for the class, but you can handle it with the [ClassCleanup] , I am having trouble, because that does not work until all the tests are completed Are there.
Using Microsoft Visual Studio Test Tools Unit testing; Static class state {public fixed string thing; } [Test class] Public class class A {[Class Initialize] Public Static Wide Initialization (TestContacts CTX) {State. Ting = "hello, world!"; } [Class cleanup] Public static zero cleanup () {State.Thing = null; } [TestMethod] Public Zero Test A () {Assert.IsNotNull (state.Thing); // Verify that we have a good condition}} [test class] public class ClassB [[TestMethod] Public Zero TestB () {Assert.IsNull (state.Thing); // Verify that we have an unimplemented state // initial condition, stuff with it}}
testb fails As it runs before
class A has been cleared.
class clipl may be unreliable while running,
ClassInitialize is not ; Why does each test class depend on this shared resource for a
ClassInitialize , which clears the shared resource of the previous test class (if any) before receiving the resource?
ClassCleanup , because then this is something else Not when it is run (because There will be no more test classes.)
Comments
Post a Comment