问题描述
正如标题所述-我找不到在Windows Store测试项目中包含文件的方法. (一个标准的.NET测试项目可以正常工作)
As the title says - I can't find a way of including a file with a windows store test project. (A standard .NET test project works fine)
右键单击解决方案并执行:添加新项目-> C#-> Windows应用商店->单元测试库(Windows应用商店应用)
Right click on the solution and execute : Add new project -> C# -> Windows Store -> Unit test library (Windows store apps)
您将获得以下样板,并在其中添加了DeploymentItem属性:
You get this boilerplate, to which I have added the DeploymentItem attribute:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
namespace UnitTestLibrary1
{
[TestClass]
public class UnitTest1
{
[TestMethod]
// this does not compile; DeploymentItem attribute not found
[DeploymentItem("wibble.txt")]
public void TestMethod1()
{
}
}
}
那我想念什么?难道根本不可能在Windows存储单元测试中包含数据,还是我需要一种不同的方法?
So what am I missing? Is it simply not possible to include data in windows store unit tests, or do I need a different approach?
推荐答案
我部署数据文件的方式是使用构建后的副本.我将数据保存在项目中的"TestData"目录下,构建后将其复制到输出中.
The way I have been deploying data files is by using a post-build copy. I have my data in my project under a directory called "TestData", which gets copied to the output after a build.
在我的测试项目的属性的构建事件"选项卡中设置了以下几行:
The following lines are set in the "Build Events" tab of the my test project's properties:
if not exist "$(TargetDir)AppX" mkdir "$(TargetDir)AppX"
if not exist "$(TargetDir)AppX\TestData" mkdir "$(TargetDir)AppX\TestData"
copy /Y "$(TargetDir)TestData\*.*" "$(TargetDir)AppX\TestData\"
一些注意事项:
- 我的单元测试引用目录
TestData
下的数据文件,而不是AppX\TestData
. - 上面的构建后操作将仅复制在项目中设置为1)内容文件和2)复制到输出中的文件.
- my unit tests refer to the data files under the directory
TestData
, and notAppX\TestData
. - the post-build action above will only copy files that have been set in your project as 1) a content file and 2) as being copied to output.
这篇关于MSTest-Windows项目测试项目上不可用的DeploymentItem属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!