Running an application from a NUNIT test

I need to start nuit where I have to start the ie word.exe application first and then let it run for 50 seconds than stop it and assert how many times the value is logged. I have the code below that will read a log file and assert if it is true or not. But I'm not sure how to start the application from NUNIT and let it run for 50 seconds, than to stop it and then run the test.

So, in the next test, I have to run the xyz.exe application, first let it run for 50 seconds, then I stop and assert. Any ideas how to do this. thank

- [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);
       }

      

+3


source to share


1 answer


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

      



+3


source







All Articles