Ramppy Dumppy
Ramppy Dumppy

Reputation: 2817

Running console app as a part of integration test c#

I need to create a integration test that will call a console application. Is there a way to run the console apps inside integration test?

Upvotes: 0

Views: 2623

Answers (2)

Maksim Simkin
Maksim Simkin

Reputation: 9679

If you console Application returns some value, you could analyse it in your test, something like:

Process P = Process.Start(path, param);
P.WaitForExit();
int result = P.ExitCode;
Assert.AreEqual(0, result);

path is path to your console application exe and param are parameters you want to provide..

Upvotes: 0

nozzleman
nozzleman

Reputation: 9649

There are probably many ways to tackle this issue, however, given the little details, there are two ways which I can come up with

Starting the app in another process

var consoleApp = Process.Start("path/to/your/app.exe");
consoleApp.WaitForExit();

Executing the Main Method of the App

This would be the best way to do it, provided the UnitTestProject has a reference to your ConsoleApp (Project or assembly-reference)

Program.Main();

Upvotes: 2

Related Questions