如果所有测试都通过,MSTest不会创建测试部署文件夹和测试结果

时间:2015-10-24 00:13:17

标签: c# mstest

我正在使用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

如何实现这一目标? 感谢

1 个答案:

答案 0 :(得分:0)

指定.testsettings文件并在其中设置属性以部署测试。您在此处描述的过程称为部署。如果不部署测试,则mstest将不会创建添加工作目录。它将从其构建放置位置执行您的测试程序集。 .testsettings可用于Visual Studio测试执行和cmd

有关更多信息,请参阅

  

this MSDN article