Xml file not copying to test output directory

后端 未结 4 1705
不知归路
不知归路 2021-02-06 21:19

Visual Studio 2010, x64 machine, using the built-in web server to host a WCF service with a set of unit tests using the built-in test framework.

I have an XML file that

相关标签:
4条回答
  • 2021-02-06 21:54

    look into using this attribute over the tests that require the xml file:

    http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.deploymentitemattribute.aspx

    0 讨论(0)
  • 2021-02-06 21:55

    Try annotating your test with the DeploymentItem attribute: http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.deploymentitemattribute(v=VS.100).aspx

    Here's a code snippet from the documentation:

      [TestClass]
        public class UnitTest1
        {
            [TestMethod()]
            [DeploymentItem("testFile1.txt")]
            public void ConstructorTest()
            {
                // Create the file to deploy
                Car.CarInfo();
                string file = "testFile1.txt";
                // Check if the created file exists in the deployment directory
                Assert.IsTrue(File.Exists(file), "deployment failed: " + file +
                    " did not get deployed");
            }
        }
    
    0 讨论(0)
  • 2021-02-06 21:58

    I was facing the issue like, one of my file was not getting copied in to out folder even if i have entered that file name in local.testSettings and set property as "Copy Always".

    Following steps has solved my problem:

    1. Open Test Menu
    2. Select Test Settings
    3. Select option "Select Test Settings file"
    4. Select your .testsettings file from Open Settings File window
    5. Make sure that Selected .testsettings file is checked under Test -> Test Settings

    Hope this will help some one.

    0 讨论(0)
  • 2021-02-06 22:15

    I've been wrestling with deploymentattribute for a while now, and have finally just given up. Instead I'm just manually copying my files over to a test directory and then deleting them once finished:

    Testfile locations:

    Private _locationOfTestFilesToBeCopied As String = "C:\...\TestFilesToBeCopied"
    Private _locationOfTestFiles As String = "C:\...\TestFiles"
    

    Initialize method:

    <TestInitialize()>
    Public Sub Setup()
        DeleteCopiedTestFiles()
        CopyTestFilesToTestDirectory()
    End Sub
    

    Copy and delete methods:

    Private Sub CopyTestFilesToTestDirectory()
        Dim sourceDirectory As New DirectoryInfo(_locationOfTestFilesToBeCopied)
    
        For Each fileInfo As FileInfo In sourceDirectory.GetFiles
            fileInfo.CopyTo(_locationOfTestFiles & "\" & fileInfo.Name, True)
        Next
    
        sourceDirectory = Nothing
    End Sub
    
    Private Sub DeleteCopiedTestFiles()
        Dim sourceDirectory As New DirectoryInfo(_locationOfTestFiles)
    
        For Each fileInfo As FileInfo In sourceDirectory.GetFiles
            fileInfo.Delete()
        Next
    
        sourceDirectory = Nothing
    End Sub
    

    I have found this works well

    0 讨论(0)
提交回复
热议问题