I have a Unit Test project with 20+ .cs files. I want to run some setup code before each individual test. Kinda like how the [TestInitialize] attribute works. However, I’d need to put that attribute on all 20+ of my .cs files.
Is there a way to centralize the initializing code in one place for every test in my entire project?
Thanks!
-Mike
Mike the only bootstrapping hooks are [ClassInitialize] and [TestInitialize] and their teardown counterparts. In cases like these I just externalized the common logic into its own class, essentially follow normal DRY and SoC practices. Typically I have several services and providers defined within my test assemblies and the xInitialize methods just have 1 or 2 lines of code to call the approperiate provider. That being said mpistrich’s answer is perfectly acceptable as well, I perfer layering over inheritence.