DeploymentItem
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
[[MSTest]]
&color(red){※前提条件:本情報はMSTestV2を基づいて説明して...
#contents
* DeploymentItemAttribute [#d05af775]
&color(red){和下面有冲突};
MSTest V2 框架引入了 DeploymentItemAttribute,用于将指定...
它既可以用于测试类(标有 TestClass 属性的类),也可以用于...
用户可以使用多个属性实例来指定多个项。
可在此处查看其构造函数。
https://learn.microsoft.com/zh-cn/visualstudio/test/usin...
#codeprettify{{
[TestClass]
[DeploymentItem(@"C:\classLevelDepItem.xml")] // Copy f...
public class UnitTest1
{
[TestMethod]
[DeploymentItem(@"..\..\methodLevelDepItem1.xml")] ...
[DeploymentItem(@"C:\DataFiles\methodLevelDepItem2.xm...
public void TestMethod1()
{
string textFromFile = File.ReadAllText("classLeve...
}
}
}}
* 问题 [#k183a83f]
.Net Core projects 里面已经不支持 DeploymentItem 了,为了...
* 解决方案 [#kdc4567b]
#codeprettify{{
// Declare this property - this is set by MSTest
public TestContext TestContext { get; set; }
// In test initialization - note the signature should be ...
// A static void method with one argument of type TestCon...
[TestInitialize]
public void TestSetup()
{
var testName = TestContext.TestName;
var method = new StackFrame().GetMethod().DeclaringTy...
var attributes = method.GetCustomAttributes(typeof(De...
foreach(DeploymentItemAttribute att in attributes)
{
var origin = Path.Combine(Path.GetDirectoryName(A...
var targetDir = Path.Combine(Path.GetDirectoryNam...
// Creates dir for deployment item
Directory.CreateDirectory(targetDir);
// Copies item
try
{
File.Copy(origin, targetDir);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Error cop...
}
}
}
}}
#hr();
コメント:
#comment_kcaptcha
終了行:
[[MSTest]]
&color(red){※前提条件:本情報はMSTestV2を基づいて説明して...
#contents
* DeploymentItemAttribute [#d05af775]
&color(red){和下面有冲突};
MSTest V2 框架引入了 DeploymentItemAttribute,用于将指定...
它既可以用于测试类(标有 TestClass 属性的类),也可以用于...
用户可以使用多个属性实例来指定多个项。
可在此处查看其构造函数。
https://learn.microsoft.com/zh-cn/visualstudio/test/usin...
#codeprettify{{
[TestClass]
[DeploymentItem(@"C:\classLevelDepItem.xml")] // Copy f...
public class UnitTest1
{
[TestMethod]
[DeploymentItem(@"..\..\methodLevelDepItem1.xml")] ...
[DeploymentItem(@"C:\DataFiles\methodLevelDepItem2.xm...
public void TestMethod1()
{
string textFromFile = File.ReadAllText("classLeve...
}
}
}}
* 问题 [#k183a83f]
.Net Core projects 里面已经不支持 DeploymentItem 了,为了...
* 解决方案 [#kdc4567b]
#codeprettify{{
// Declare this property - this is set by MSTest
public TestContext TestContext { get; set; }
// In test initialization - note the signature should be ...
// A static void method with one argument of type TestCon...
[TestInitialize]
public void TestSetup()
{
var testName = TestContext.TestName;
var method = new StackFrame().GetMethod().DeclaringTy...
var attributes = method.GetCustomAttributes(typeof(De...
foreach(DeploymentItemAttribute att in attributes)
{
var origin = Path.Combine(Path.GetDirectoryName(A...
var targetDir = Path.Combine(Path.GetDirectoryNam...
// Creates dir for deployment item
Directory.CreateDirectory(targetDir);
// Copies item
try
{
File.Copy(origin, targetDir);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Error cop...
}
}
}
}}
#hr();
コメント:
#comment_kcaptcha
ページ名: