我有一个问题,一旦我点击编译,mstest cmd提示出现然后它崩溃/消失,我的测试不会被执行。 这是代码:
public void test(String testContainer, String testName)
{
// String Path = @"C:\Program Files\Microsoft Visual Studio 10.0 Common7\IDE\mstest.exe";
String Path = @"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\mstest.exe";
// String Path = @"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat""";
Process myProcess = new Process();
// ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(Path, "/testsettings:local.testsettings /testcontainer:" + testContainer + " /test:" + testName);
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(Path, "MSTest/testcontainer:" + testContainer + " /test:" + testName + @"/testcategory:""ActionCol""");
myProcessStartInfo.UseShellExecute = false;
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();
// MessageBox.Show(x + "\n" + y);
}
这就是我称之为这种方法的方式:
private void button3_Click(object sender, EventArgs e)
{
x = @"C:\Users\butoiu.edward\Desktop\Lucru\SimarpiUnitTest\GestcollTestSolution\CodedUITestProject\bin\Debug\GestcollTestProject.dll";
y = "ActionCollInsert";
test(x, y);
}
我做错了什么?这里真的需要一些帮助,提前谢谢
编辑1 - 这是我的另一个项目中的测试方法的样子。忘了提及我在同一个解决方案下有2个项目(没有改变一件事,但我认为它值得一提)
[TestMethod(), TestCategory("ActionCol")]
public void ActionCollInsert()
{
MessageBox.Show("test");
//using the proper map
var actionColTest = new ActionColMap();
//actionColTest.ActionColOpen1();
// actionColTest.ActionColSlider();
actionColTest.ActionColHideCollumns();
actionColTest.ActionColInsert();
actionColTest.ActionColInsertCode();
actionColTest.ActionColInsertDesc();
actionColTest.ActionColSave();
}
EDIT2 - 我如何启动DEV-CMD - 使用shell启动我的cmd,从它的快捷方式位置为我修复了一些东西。当我解决这个问题时,出现了一个新问题。我无法将参数传递给cmd,我的意思是没有任何反应。
public void test(String testContainer, String testName)
{
// String Path = @"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\mstest.exe";
String Path = @"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Visual Studio 2012\Visual Studio Tools\Developer Command Prompt for VS2012.lnk";
Process myProcess = new Process();
// ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(Path, "/testsettings:local.testsettings /testcontainer:" + testContainer + " /test:" + testName);
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(Path, "MSTest/testcontainer:" + testContainer + " /test:" + testName );
myProcessStartInfo.UseShellExecute = true;
myProcessStartInfo.Arguments = "blah blah"; // - this ain't working !!!!
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();
}
EDIT3 - 我能够启动一个cmd并将一些参数传递给它(来源:Passing an argument to cmd.exe)。但是将路径更改为我的dev cmd提示符将不会自动插入参数。需要一些帮助,/ c对dev cmd没有影响。
ProcessStartInfo proc = new ProcessStartInfo();
proc.FileName = Path;
proc.Arguments = @"/c ping 10.2.2.125";
proc.UseShellExecute = true;
Process.Start(proc);
答案 0 :(得分:1)
您可以尝试创建批处理脚本,该脚本可以为mstest构建环境并相应地触发测试
请在下面找到示例。您只需为系统替换 vcvarsall.bat 的正确路径
cd\
cd "Program Files <x86>"\"Microsoft Visual Studio 12.0"\VC
call "vcvarsall.bat"
cd\
C:
Mstest /testcontainer:Test.dll /resultsfile:result.trx