AssemblyCleanup does not shoot

I have several methods that are used to initialize and clean up the database that I use with my tests, but my methods with the AssemblyInitialize and AssemblyCleanup attributes do not start.

Any ideas?

[TestInitialize] public void Init() { LoadData(); } [AssemblyInitialize] public void AssemblyInit() { } public void LoadData(string testDataFileName = "TestData.xml") { connectionString = ConfigurationManager.ConnectionStrings["NDbUnit"].ConnectionString; mySqlDatabase = new NDbUnit.Core.SqlClient.SqlDbUnitTest(connectionString); mySqlDatabase.ReadXmlSchema("DataSet.xsd"); mySqlDatabase.ReadXml(testDataFileName); mySqlDatabase.PerformDbOperation(NDbUnit.Core.DbOperationFlag.CleanInsertIdentity); dataSet = mySqlDatabase.CopyDataSet(); } [AssemblyCleanup] public void RemoveDatabases() { List<string> databasesToDelete = new List<string>(); ServerConnection serverConnection = new ServerConnection(new SqlConnection(connectionString)); Server server = new Server(serverConnection); foreach (Database db in server.Databases) { if (db.Name.ToLower().Contains(testDatabaseIdentifier)) { databasesToDelete.Add(db.Name); } } databasesToDelete.ForEach(x => { Database db = new Database(server, x); db.Refresh(); db.Drop(); }); } [TestCleanup] public void CleanUpData() { mySqlDatabase.PerformDbOperation(NDbUnit.Core.DbOperationFlag.DeleteAll); } 
+7
source share
2 answers

Figured it out. Those methods that were published earlier were in the base class, and the rest of the test cases were going to inherit, but the base class was not marked as TestClass. Apparently, without it, you can still run the TestInitialize and TestCleanup methods, but not the Assembly> elements. <

+12
source

AssemblyCleanup -

 static public void AssemblyCleanup 

Make sure its class is public and has the TestClass attribute

+5
source

All Articles