quip
quip

Reputation: 3694

Can MSTest run a specific method each time it startsup?

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")]

Upvotes: 6

Views: 723

Answers (1)

SaaS Developer
SaaS Developer

Reputation: 9895

Have you tried [AssemblyInitialize]?

Upvotes: 6

Related Questions