Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can MSTest run a specific method each time it startsup?

Tags:

mstest

Question

Is there a way to have a method that will always run anytime that test assembly is run through MSTest?

Similar to how the [TestInitialize] and [ClassInitialize] attributes work, but for the entire assembly. I do not want to have to add code to every test class's [ClassInitialize] method.

Reasoning

Some of my tests interact with the database. They delete data and other things that would be very harmful to a production database. There is only a configuration file that tells my unit test project to run against the non-production database.

I would feel better if there was a method that would run on startup that would say "Okay Database name is not 'production'"

Ideas

Log4Net uses an assembly attribute to configure itself.

using log4net.Config;
[assembly: XmlConfigurator()]

Perhaps I can do something simliar?

[assembly:  CheckDatabaseNameNot("production")]
like image 784
quip Avatar asked Oct 22 '08 21:10

quip


1 Answers

Have you tried [AssemblyInitialize]?

like image 60
SaaS Developer Avatar answered Oct 12 '22 04:10

SaaS Developer