vendredi 25 décembre 2015

Is it possible to display a windows Form from within unit tests?

So i'm writing this computer vision application in C# using opencv, Emgu and visual studio.

I'm trying to write a few unit tests using the built in unit tests from Microsoft and I'm starting to think that I'm trying to do something really rare here because I simply can't find the answer anywhere on the internet.

The application is a console application because it won't have a user interface but I'd like to display a few debug images while I'm coding it. I have created a Form using the designer which has a few PictureBox in it.

I simply would like to be able to do something like:

DebugViewer debugViewer = new DebugViewer();
debugViewer.SetPicture(debugImage);
debugViewer.Show();

Where DebugViewer is the Form I created and SetPicture simply updates the image of a PictureBox.

The problem is that the form never shows up. Nothing appears in the taskbar even with the ShowInTaskbar property set.

I tried the same code running from a main function and it worked correctly. The problem seems to be with trying to run this from a unit test.

I also successfully displayed images using opencv imShow function even from the unit tests so I'm certain it is possible to open windows from unit tests but I don't know why the Forms don't show up.

I realize opening debug windows from unit test doesn't make much sense but since I've lost an entire afternoon trying to solve this I thought I should at least satisfy my curiosity.

Thanks a lot.

Aucun commentaire:

Enregistrer un commentaire