MSTest

※前提条件:本情報はMSTestV2を基づいて説明してる

问题 [edit]

.Net Core projects 里面已经不支持 DeploymentItem 了,为了从 MSTest V1 迁移到 V2

解决方案 [edit]

// Declare this property - this is set by MSTest
public TestContext TestContext { get; set; }

// In test initialization - note the signature should be exactly this
// A static void method with one argument of type TestContext 
[TestInitialize]
public void TestSetup()
{
    var testName = TestContext.TestName;
    var method = new StackFrame().GetMethod().DeclaringType.GetMethod(testName);
    var attributes = method.GetCustomAttributes(typeof(DeploymentItemAttribute)).ToArray();
    foreach(DeploymentItemAttribute att in attributes)
    {
        var origin = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), att.Path);
        var targetDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), att.OutputDirectory);
        // Creates dir for deployment item
        Directory.CreateDirectory(targetDir);
        // Copies item
        try
        {
            File.Copy(origin, targetDir);
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine("Error copying deployment item {0} to {1} message {2}", origin, targetDir, ex.Message);
        }
    }
}

コメント:



(画像の文字列を入力して下さい)

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS