Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to display progress during the execution of a Visual Studio TestMethod?

Is there a way I can show the progress of a single TestMethod In Visual Studio 2008 ?

Within a set of unit tests, I have a single TestMethod that runs for a very, very long time - normally it will take between 30 and 60 minutes. I've set the Timeout using the [Timeout] attribute, no problem there. But I'd like to be able to get a visual indication of progress of the test.

I know the Test Results window gives a visual progress update of all the test methods. What I want is a visual progress update of a single method. In a WinForms app I would popup a ProgressBar control. In a console app, I would position the cursor and display a status message. But this is a unit test. I can write to the TestContext, but that window is not viewable until the test completes.


EDIT: I know there is a way to do it; it's all just software, so there is always a way. But what is a simple, practical way?

One way to do it is to create a TestMethodProgressMonitor.exe app, which reads from a named pipe, and updates a progress bar based on the messages that come through the pipe. The TestMethod can shellExec the TestMethodProgressMonitor.exe, then write to the named pipe. When finished, maybe there is a well-known shutdown command that the TestMethod sends to the TestMethodProgressMonitor.exe app.

Another option is to construct the TestMethodProgressMonitor.exe as a COM server, and the TestMethod can use COM (DCOM) to update a hosted progress bar within the app.

Another option is to use the user32.dll SendMessage() method to send a WM_COPYDATA message to the monitor app. This is sometimes done for remote control of apps.

Those are some of the possibilities. Before I set about building one of them, I'd like to know if there is a simpler way.

like image 402
Cheeso Avatar asked Jun 16 '09 17:06

Cheeso


2 Answers

I just start a GUI thread with a Window that has the progressbar.

Here's a snippet to get you started. It simply pops up MyProgressWindow in another thread (rather than another process).

[ClassInitialize()]
static public void MyClassInitialize(TestContext testContext)
{
    start_app_in_gui_thread();
}

static Thread t;

private static void start_app_in_gui_thread()
{
    t = new Thread(() => {
        var w = new MyProgressWindow();
        var app = new App();
        app.ShutdownMode = ShutdownMode.OnMainWindowClose;
        app.Run(w);
    });
    t.SetApartmentState(ApartmentState.STA);
    t.Start();
}
like image 127
Ray Avatar answered Sep 25 '22 02:09

Ray


For my long running tests I use the Trace APIs to attach a trace listener (DbgView or something custom).

Makes it dead simple to see what's going on without having to jump through any hoops.

This isn't going to give you a progress bar experience (though you could write one pretty easily).

like image 30
Robert Horvick Avatar answered Sep 24 '22 02:09

Robert Horvick