我必须运行一个nuit,首先我必须启动一个应用程序,即word.exe,然后让它运行50秒而不是停止它并断言记录值的次数。 我有下面的代码将读取日志文件并断言它是否为真。但 我不知道如何从NUNIT启动应用程序并让它运行50秒而不是停止运行测试。
所以在下面的测试中我必须先启动我的应用程序xyz.exe,让它运行50秒,而不是停止并断言。任何想法如何完成它。谢谢
- [Test]
public void logtest()
{
// arrange
ILog log = LogManager.GetLogger(typeof (LoggingIntegrationTests));
string = "Error 2";
// act
log.Info(dataToLog);
// assert
LogManager.Shutdown();
var matches = Regex.Matches(File.ReadAllText(logfile), dataToLog);
Assert.AreEqual(3, matches.Count);
}
答案 0 :(得分:3)
using System.Diagnostics;
using System.Threading;
[Test]
public void logtest()
{
// ...
Process proc = Process.Start(@"c:\windows\system32\notepad.exe");
if ( null == proc )
Assert.Fail("Could not start process, maybe an existing process has been reused?");
Thread.Sleep(50000);
proc.Kill();
// ...
}