21

I'm using a Visual Studio Test project, am modifying the test config with deployment files, etc. (through the VS GUI) and now I need to write a Startup script for the test run.

I have no clue what language or file type or mechanism is used for these scripts. Need a tip.

John K
  • 28,441
  • 31
  • 139
  • 229

1 Answers1

51

Create a unit test in your test project. In the unit test class, create methods with the [TestInitialize] and [TestCleanup] attributes. They will be run before/after each test method.

Or, if you want to run before/after all test in that class, create static methods with [ClassInitialize] and [ClassCleanup] attributes.

Lastly, to run before/after all tests in the assembly, create static methods with [AssemblyInitialize] and [AssemblyCleanup] attributes.

spoulson
  • 21,335
  • 15
  • 77
  • 102
  • 2
    Thanks for the tip - it sent me in the right direction. From there I found `AssemblyInitialize` and `AssemblyCleanup` which is what I need in this case. Can you append these two Attributes to your answer for posterity... – John K Feb 21 '10 at 02:46
  • Is there any advantage to using [ClassInitialize] instead of using the Class constructor? – Philip Nov 24 '15 at 11:58