编码的 UI 测试 - 将 exe 文件作为清理脚本运行
我正在尝试从每次测试运行后生成的已完成测试 .trx 文件自动生成 .pdf 文件。我创建了一个 .exe,它可以获取这个 trx 文件并将其转换为 pdf。当我单独运行该应用程序时,它工作正常,但是当我尝试将其用作清理脚本时,我遇到了麻烦。测试运行良好,并生成了测试结果文件,但是当它运行清理方法时,它似乎找不到测试结果文件。
我也尝试过使用 AssemblyCleanup() 方法,但这会产生类似的错误。
[TestClass]
public static class AssemblyClean
{
[AssemblyCleanup()]
public static void AssemblyCleanup()
{
System.Diagnostics.Process.Start("XMLtoPDFConverter.exe");
}
}
任何帮助将不胜感激,谢谢。
I'm trying to automatically generate a .pdf file from the completed test .trx file that is generated after every test run. I created a .exe that can take this trx file and convert it into a pdf. The application works fine when i run it on its own, but im having trouble when i try and use it as a cleanup script. The test runs fine, and generated the test results file, but when it runs the cleanup method it cant seem to find the test results file.
I've also tried using the AssemblyCleanup() method but that is producing a similar error.
[TestClass]
public static class AssemblyClean
{
[AssemblyCleanup()]
public static void AssemblyCleanup()
{
System.Diagnostics.Process.Start("XMLtoPDFConverter.exe");
}
}
Any help would be appreciated, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
直到一切运行之后,测试结果文件可能才会被创建。尝试在 XMLtoPDFConverter.exe 中设置 5 或 10 秒的
睡眠
。这样,您的进程将由AssemblyCleanup()
启动,但在有足够的时间创建 .trx 文件之前,它不会查找 .trx 文件。The test results file is probably not being created until after everything runs. Try putting a 5 or 10 second
Sleep
in your XMLtoPDFConverter.exe. That way, your process will be started by theAssemblyCleanup()
, but it won't look for the .trx file until after there's been enough time for it to be created.似乎所需要做的就是关闭解决方案并重新打开它。这似乎使 Visual Studio 能够识别 exe 文件。每当我更改 exe 文件时,我都必须做同样的事情。另外,对于将来遇到类似问题的任何人,我坚持使用 AssemblyCleanup() 方法,并且在每次测试运行后执行得很好,无论成功与否。
It seems that all that was necessary was to close the solution and reopen it. This seems to of made visual studio recognize the exe file. I have to do the same thing whenever i make changes to the exe file. Also for anyone that runs into a similar issue in the future, I stuck with the AssemblyCleanup() method and that executes just fine after every test run, successful or not.