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 [ClassCleanup] , I am having trouble, because that does not work until all the tests are completed Are there.

Here's a simple example:

  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}}   

at least on my machine, testb fails As it runs before class A has been cleared.

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 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?

Once the sharing resource is not released, the final exam is for the class, but you can handle it with the ClassCleanup , because then this is something else Not when it is run (because There will be no more test classes.)

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -