以编程方式运行编码的UI测试 [英] Run Coded UI tests programatically
问题描述
HI
我正在尝试以编程方式运行编码的UI测试。
我添加了belwo两个引用
1. Microsoft.VisualStudio.TestPlatform.ObjectModel.dll位于"Visual_Studio_Directory \ Common7 \IDE \CommonExtensions" \微软\ TestWindow" b
2. Microsoft.VisualStudio.TestPlatform.Extensions.VSTestIntegration.dll位于"Visual_Studio_Directory \ Common7 \IDE \CommonExtensions" \微软\ TestWindow \Extensions"
并尝试了以下代码:
$
string DeployItems(string source )
      {
          string deploymentPath = Path.Combine(GetTempFolderPath()," TestRunner");
          if(Directory.Exists(deploymentPath)== false)
              Directory.CreateDirectory(deploymentPath);
          DateTime dt = DateTime.Now;
          string dirName = string.Format(" Deploy_ {0} {1} - {2} - {3} {4} _ {5} _ {6} _ {7}",Environment.UserName,dt.Day。 ToString(),dt.Month.ToString(),dt.Year.ToString(),
dt.Hour.ToString( ),dt.Minute.ToString(),dt.Second.ToString(),dt.Millisecond.ToString());
$
          DirectoryInfo dirInfo = Directory.CreateDirectory(Path.Combine(deploymentPath,dirName));
          DirectoryInfo dirIn = Directory.CreateDirectory(Path.Combine(dirInfo.FullName," In"));
          Directory.CreateDirectory(Path.Combine(dirIn.FullName,Environment.MachineName));
          DirectoryInfo dirOut = Directory.CreateDirectory(Path.Combine(dirInfo.FullName," Out"));
$
          Microsoft.VisualBasic.Devices.Computer comp = new Microsoft.VisualBasic.Devices.Computer();
          comp.FileSystem.CopyDirectory(source,dirOut.FullName);
          return dirInfo.FullName;
      }
字符串deploymentPath = DeployItems("包含程序集的源目录);
$
string dllName =" Name_Assembly_ThatHas_TestMethods" ;; $
string nameOfTestClass =" ; NameOfTestClassThatHasTestMethod" ;;
$
string nameOfTestMethod =" NameOfTestMethodThatWeWantToRun";
$
UnitTestRunner testRunner = new UnitTestRunner(deploymentPath,dllName,false);
//设置测试运行属性
字典<字符串,对象> properties = PrepareTestRunProperties(deploymentPath,nameOfTestClass,nameOfTestMethod);
$
TestMethod testMethod = new TestMethod(nameOfTestMethod,nameOfTestClass,dllName,false);
UnitTestElement testElement = new UnitTestElement(testMethod);
$
UnitTestResult [] testResults = testRunner.RunDataDrivenTest(nameOfTestMethod,nameOfTestClass,false,properties);
if(testResults [0] .Outcome == UnitTestOutcome.Passed)
{
Console.WriteLine("Test Case Passed");
}
其他
{
Console.WriteLine("测试用例失败,错误"+ testResults [0 ] .ErrorMessage);
}
$
字典<字符串,对象> PrepareTestRunProperties(string deploymentPath,string nameOfTestClass,string nameOfTestMethod)
{
Dictionary< string,object> properties = new
Dictionary< string,object>();
properties.Add(" TestRunDirectory",deploymentPath);
properties.Add(" DeploymentDirectory",
Path.Combine(deploymentPath," Out"));
  ; properties.Add(" ResultsDirectory",
Path.Combine(deploymentPath," In"));
properties.Add(" ; TestRunResultsDirectory",
Path.Combine(deploymentPath," In",
Environment.MachineName));
properties.Add(" TestResultsDirectory",
Path.Combine(deploymentPath," In"));
properties .Add(" TestDir",Path.Combine(deploymentPath));
properties.Add(" TestDeploymentDir",
Path.Combine (deploymentPath,"Out"));
$
properties.Add(" TestLog sDir",Path.Combine(deploymentPath,
" In",Environment.MachineName));
properties.Add(" FullyQualifiedTestClassName" ,
nameOfTestClass);
properties.Add(" TestName",nameOfTestMethod);
返回属性; $
}
我是部署路径,我给出了调试文件夹的路径
但它显示在程序集中找不到类。
错误"无法获得XXXTests类型。错误:System.IO.FileNotFoundException:无法加载文件或程序集'
请帮助
嗨thakurAnunay,
欢迎来到MSDN论坛。
请尝试使用以下方法解决此问题:
1.请在
属性中检查值"复制本地=真实"这两个程序集。
2.构建解决方案后,请检查这两个程序集是否正确复制到"C:\ Users \Admin \source \repos \CodedUITestProject1 \CodedUITestProject1 \ bin \Debug"路径。
3.请尝试在代码中指定程序集路径。
希望可以帮到你。
问候,
Judyzh 跨度>
HI
I am trying to run coded UI test programatically.
I added the belwo two references
1. Microsoft.VisualStudio.TestPlatform.ObjectModel.dll located at "Visual_Studio_Directory\Common7\IDE\CommonExtensions\Microsoft\TestWindow"
2. Microsoft.VisualStudio.TestPlatform.Extensions.VSTestIntegration.dll located at "Visual_Studio_Directory\Common7\IDE\CommonExtensions\Microsoft\TestWindow\Extensions"
And tried the below code:
string DeployItems(string source)
{
string deploymentPath = Path.Combine(GetTempFolderPath(), "TestRunner");
if (Directory.Exists(deploymentPath) == false)
Directory.CreateDirectory(deploymentPath);
DateTime dt = DateTime.Now;
string dirName = string.Format("Deploy_{0} {1}-{2}-{3} {4}_{5}_{6}_{7}", Environment.UserName, dt.Day.ToString(), dt.Month.ToString(), dt.Year.ToString(),
dt.Hour.ToString(), dt.Minute.ToString(), dt.Second.ToString(), dt.Millisecond.ToString());
DirectoryInfo dirInfo = Directory.CreateDirectory(Path.Combine(deploymentPath, dirName));
DirectoryInfo dirIn = Directory.CreateDirectory(Path.Combine(dirInfo.FullName, "In"));
Directory.CreateDirectory(Path.Combine(dirIn.FullName, Environment.MachineName));
DirectoryInfo dirOut = Directory.CreateDirectory(Path.Combine(dirInfo.FullName, "Out"));
Microsoft.VisualBasic.Devices.Computer comp = new Microsoft.VisualBasic.Devices.Computer();
comp.FileSystem.CopyDirectory(source, dirOut.FullName);
return dirInfo.FullName;
}
string deploymentPath = DeployItems("Source directory containing the assemblies");
string dllName = "Name_Assembly_ThatHas_TestMethods";
string nameOfTestClass = "NameOfTestClassThatHasTestMethod";
string nameOfTestMethod = "NameOfTestMethodThatWeWantToRun";
UnitTestRunner testRunner = new UnitTestRunner(deploymentPath, dllName, false);
// Set the test run properties
Dictionary<string, object> properties = PrepareTestRunProperties(deploymentPath, nameOfTestClass, nameOfTestMethod);
TestMethod testMethod = new TestMethod(nameOfTestMethod, nameOfTestClass, dllName, false);
UnitTestElement testElement = new UnitTestElement(testMethod);
UnitTestResult[] testResults = testRunner.RunDataDrivenTest(nameOfTestMethod, nameOfTestClass, false, properties);
if (testResults[0].Outcome == UnitTestOutcome.Passed)
{
Console.WriteLine("Test Case Passed");
}
else
{
Console.WriteLine("Test Case Failed with error " + testResults[0].ErrorMessage);
}
Dictionary<string, object> PrepareTestRunProperties(string deploymentPath, string nameOfTestClass, string nameOfTestMethod)
{
Dictionary<string, object> properties = new
Dictionary<string, object>();
properties.Add("TestRunDirectory", deploymentPath);
properties.Add("DeploymentDirectory",
Path.Combine(deploymentPath, "Out"));
properties.Add("ResultsDirectory",
Path.Combine(deploymentPath, "In"));
properties.Add("TestRunResultsDirectory",
Path.Combine(deploymentPath, "In",
Environment.MachineName));
properties.Add("TestResultsDirectory",
Path.Combine(deploymentPath, "In"));
properties.Add("TestDir", Path.Combine(deploymentPath));
properties.Add("TestDeploymentDir",
Path.Combine(deploymentPath, "Out"));
properties.Add("TestLogsDir", Path.Combine(deploymentPath,
"In", Environment.MachineName));
properties.Add("FullyQualifiedTestClassName",
nameOfTestClass);
properties.Add("TestName", nameOfTestMethod);
return properties;
}
I the deployment path i am giving the path of debug folder
But it shows class not found in the assembly.
Error"Unable to get type XXXTests. Error: System.IO.FileNotFoundException: Could not load file or assembly '
Please help
Hi thakurAnunay,
Welcome to the MSDN forum.
Please have a try with the following to troubleshoot this issue:
1.Please check the value "Copy Local =True" in Properties of that two assemblies.
2.After build solution, please check those two assemblies copy to "C:\Users\Admin\source\repos\CodedUITestProject1\CodedUITestProject1\bin\Debug" path correctly.
3.Please try to specify assemblies path in your code.
Hope could help you.
Regards,
Judyzh
这篇关于以编程方式运行编码的UI测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!