我有一些方法用于初始化和清理用于测试的数据库,但是我的带有AssemblyInitialize和AssemblyCleanup属性的方法无法启动。
有任何想法吗?
[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);
}
最佳答案
弄清楚了。较早发布的那些方法在其他测试用例都将要继承的基类中,但是该基类未标记为TestClass。显然,没有它,您仍然可以运行TestInitialize和TestCleanup方法,但不能运行Assembly方法>。<
关于c# - AssemblyCleanup不触发,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5171531/