J. Davidson
J. Davidson

Reputation: 3317

Starting an application from NUNIT Test

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

So in the following test I have to start my application xyz.exe first let it run for 50 seconds than I stop and assert. Any ideas how to get it done. thanks

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

Upvotes: 3

Views: 1345

Answers (1)

metalheart
metalheart

Reputation: 3809

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

Upvotes: 3

Related Questions