我正在使用MSTest来测试我的C#代码。
问题是,在运行测试时,我还在测试输出目录中写了一些文件:
class Chart < ActiveRecord::Base
belongs_to :chart_type
belongs_to :section
has_many :data_points, dependent: :destroy
translates :name
globalize_accessors :attributes => [:name], locales: languages
validates :name, presence: true
accepts_nested_attributes_for :data_points
def self.languages
[:en, :fr]
end
我的解决方案在[TestMethod]
public void TestSomething() {
// Do some Assert stuff here...
TestContext context = GetContext();
string folderPath = Path.GetFullPath(context.DeploymentDirectory);
string filePath = Path.Combine(
Path.GetFullPath(this.context.TestRunDirectory),
"myfile.txt");
using (StreamWriter writer = File.CreateText(filePath)) {
writer.Write(content);
}
}
。
当我运行测试但失败时,我可以看到正在创建文件夹C:\Users\MyUser\Documents\MySolution
文件夹,没有MySolution\TestResults\Deploy_myuser 2015-10-23 21_12_51
文件!但有.trx
!
没有创建文件夹。
我想始终生成测试结果文件夹。我不在乎传递时是否生成MySolution\TestResults\Deploy_myuser 2015-10-23 21_12_51\Out\myfile.txt
文件(只要失败时),但我希望始终在测试文件夹中写入.trx
。
如何实现这一目标? 感谢
答案 0 :(得分:0)
指定.testsettings
文件并在其中设置属性以部署测试。您在此处描述的过程称为部署。如果不部署测试,则mstest
将不会创建添加工作目录。它将从其构建放置位置执行您的测试程序集。 .testsettings
可用于Visual Studio测试执行和cmd
。
有关更多信息,请参阅