c# - Multiple cleanup actions on VS2008 Unit Testing -


The questions are very easy and I should know how many cleaning tests should be prepared.

I have some tests, and each test creates a separate file, I want to bind the cleaning action for each, so I can delete the specified files for each test.

Example:

  [TestMethod] Public Zero TestMethodA () {// do stuff} [TestMethod] Public Zero TestMethodB () {// do stuff} [TestCleanup] Public Zero CleanUpA () {// Clean A} [TestCleanup] Public Zero CleanUpB () {// Clean B}  

Any ideas?

Potentially, there are some options that I can see. A simple solution that can work for you, should be a class-level variable in your unit test class that stores the path of the file used by the current performance test. Each test provides that current file path to that variable. Then you can use a cleanup method that uses that variable to clean the file.

There is another idea, but a significant refactoring may be required, instead of using a dependency-injection approach, your code from the abstract file system might instead create your code / instead of opening the file, You can have an IO abstract component to create a file and then simply return a stream object to your main code. When you run your unit test, you can provide your main code with a unit trial version of the IO Abstract Component which will return MemoryStream instead of a FileStream, which will avoid the need to perform a cleanup. If someone is not clear about my description, then I can update with some examples.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -