从NUNIT测试启动一个应用程序

3

我需要运行一个NUNIT测试,首先需要启动一个应用程序,即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);
       }
1个回答

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();
    // ...
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接