簡體   English   中英

DeploymentItem不部署文件

[英]DeploymentItem not deploying files

我正在使用MS unit testing framework來測試我的C#庫。 我必須使用DeploymentItem attribute打開我正在部署的文件。 但它沒有將文件部署到Test部署目錄。

在我的Unit-test項目中,我在這個文件夾中創建了一個文件夾TestFile ,有多個文件,比方說a.txt,b.txt。

現在在我的Unit-test類中,我添加了DeploymentItem屬性。 但文件沒有被復制。

這是我的代碼。

[TestClass]
[DeploymentItem("TestFile")]
public class CustomLibraryTest
{
    public TestContext TestContext { get; set; }

    [TestMethod]
    [DeploymentItem(@"TestFiles\a.txt")]  // THis should deploy a.txt to test deployment directory
    {
        var path = TestContext.TestDeploymentDir + "a.txt";
        // Now when I debug this unit-test, and open path in explorer,
        // a.txt is not present in "TestResults\Deploy_fhafeez 2013-05-28 13_02_37\Out" folder
    }
}

我做錯了什么?

我在這個帖子中找到了兩個可能的解決方案:

  1. 將部署文件的“復制到輸出文件夾”屬性設置為“始終復制”(請參閱DeploymentItem屬性的問題
  2. 檢查Local.testsettings文件中的“啟用部署”設置(請參閱DeploymentItem屬性的問題

希望這可以幫助。

對於將來的引用,從我注意到使用VS 2015 - 您在部署項屬性中指定的路徑必須相對於構建輸出(調試文件夾)。 如果您的文件夾結構是“UnitTesting \\ TestData \\ Test.xml”,則DeploymentItem必須是DeploymentItem(“.. \\ .. \\ TestData \\ Test.xml”)在這種情況下,TestData文件夾不需要包含在UnitTesting項目中。

我有一組測試,其中副本用於某些測試但不是最新的,即使DeploymentItem屬性設置完全相同。 在完成其他所有操作后,我在解決方案上做了一個“清潔解決方案”並重新啟動並開始正確復制。 因人而異

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM