gpt4 book ai didi

c# - 使用 MSTest 从其他程序集运行测试

转载 作者:太空宇宙 更新时间:2023-11-03 13:18:14 24 4
gpt4 key购买 nike

我这里有一个问题,我一点击编译,就会出现 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);

最佳答案

您可以尝试创建批处理脚本,它可以为 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

关于c# - 使用 MSTest 从其他程序集运行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25281600/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com