Test collections can also be decorated with IClassFixture. treats collection fixtures in much the same way as class fixtures,Įxcept that the lifetime of a collection fixture object is longer: it isĬreated before any tests are run in any of the test classes in the collection,Īnd will not be cleaned up until all test classes in the collection have Here is a simple example: public class StackTests : IDisposable Sharing object instances (meaning, you get a clean copy of the contextįor context cleanup, add the IDisposable interface to your testĬlass, and put the cleanup code in the Dispose() method. Put reusable context setup code where you want to share the code without This makes the constructor a convenient place to So any code which is placed into the constructor of the test class will be creates a new instance of the test class for every test that is run, (sharing the setup and cleanup code, without sharing the object instance). When to use: when you want a clean test context for every test Class Fixtures (shared object instance across.Constructor and Dispose (shared setup/cleanup.offers several methods for sharing this setup andĬleanup code, depending on the scope of things to be shared, as well as theĮxpense associated with the setup and cleanup code. It is common for unit test classes to share setup and cleanup code (often called
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |