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











up vote
0
down vote

favorite












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.










share|improve this question


























    up vote
    0
    down vote

    favorite












    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.










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      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.










      share|improve this question













      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.







      c# winforms visual-studio unit-testing opencv






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 25 '15 at 22:46









      Felipe Castro

      43




      43
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          Is your debugViewer form shown modally or non-modally? I was just playing with unit testing and trying to display a report preview form I have. When I display the form modally, it works. When I display it non-modally, nothing displays.



          I imagine that displaying a form non-modally, where execution continues, takes everything out of scope as the unit test ends. That means the form does not display. Or, perhaps the unit testing code knows it can't display anything unless execution stops and never even displays it? Not sure. So far, though, I have been able to make several different forms pop up inside unit test methods.



          (I am sure this is not a very good answer, but I don't have the points to simply comment yet...)



          EDIT: I have run into modal forms that also do not display, and I cannot figure out why. I can debug the test, and when it comes to the line where my form is being displayed with ShowDialog(), execution pauses but no form displays. I can even inspect the form in the debug window and see that its dimensions are correct and Visible = true -- still nothing. So, I'm stumped.






          share|improve this answer






























            up vote
            0
            down vote













            I think you are trying to use the wrong tool for your problem... Dealing with GUI just for debug purpose can be frustrating...



            Check out HypnoLog, an open source tool I developed to help me debug image processing application I been writing using C# and EmguCV.



            With HypnoLog you can see the images as output in your browser, which acting as output log.



            In your case you should check HypnoLog-CSharp, and there is already a simple visualizer for images. Your code will look something like this:



            HL.log(debugImage, "image");


            note, debugImage should be image encoded in base64, see ImageVisualizer for more information.






            share|improve this answer





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














               

              draft saved


              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f34467064%2fis-it-possible-to-display-a-windows-form-from-within-unit-tests%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              0
              down vote













              Is your debugViewer form shown modally or non-modally? I was just playing with unit testing and trying to display a report preview form I have. When I display the form modally, it works. When I display it non-modally, nothing displays.



              I imagine that displaying a form non-modally, where execution continues, takes everything out of scope as the unit test ends. That means the form does not display. Or, perhaps the unit testing code knows it can't display anything unless execution stops and never even displays it? Not sure. So far, though, I have been able to make several different forms pop up inside unit test methods.



              (I am sure this is not a very good answer, but I don't have the points to simply comment yet...)



              EDIT: I have run into modal forms that also do not display, and I cannot figure out why. I can debug the test, and when it comes to the line where my form is being displayed with ShowDialog(), execution pauses but no form displays. I can even inspect the form in the debug window and see that its dimensions are correct and Visible = true -- still nothing. So, I'm stumped.






              share|improve this answer



























                up vote
                0
                down vote













                Is your debugViewer form shown modally or non-modally? I was just playing with unit testing and trying to display a report preview form I have. When I display the form modally, it works. When I display it non-modally, nothing displays.



                I imagine that displaying a form non-modally, where execution continues, takes everything out of scope as the unit test ends. That means the form does not display. Or, perhaps the unit testing code knows it can't display anything unless execution stops and never even displays it? Not sure. So far, though, I have been able to make several different forms pop up inside unit test methods.



                (I am sure this is not a very good answer, but I don't have the points to simply comment yet...)



                EDIT: I have run into modal forms that also do not display, and I cannot figure out why. I can debug the test, and when it comes to the line where my form is being displayed with ShowDialog(), execution pauses but no form displays. I can even inspect the form in the debug window and see that its dimensions are correct and Visible = true -- still nothing. So, I'm stumped.






                share|improve this answer

























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Is your debugViewer form shown modally or non-modally? I was just playing with unit testing and trying to display a report preview form I have. When I display the form modally, it works. When I display it non-modally, nothing displays.



                  I imagine that displaying a form non-modally, where execution continues, takes everything out of scope as the unit test ends. That means the form does not display. Or, perhaps the unit testing code knows it can't display anything unless execution stops and never even displays it? Not sure. So far, though, I have been able to make several different forms pop up inside unit test methods.



                  (I am sure this is not a very good answer, but I don't have the points to simply comment yet...)



                  EDIT: I have run into modal forms that also do not display, and I cannot figure out why. I can debug the test, and when it comes to the line where my form is being displayed with ShowDialog(), execution pauses but no form displays. I can even inspect the form in the debug window and see that its dimensions are correct and Visible = true -- still nothing. So, I'm stumped.






                  share|improve this answer














                  Is your debugViewer form shown modally or non-modally? I was just playing with unit testing and trying to display a report preview form I have. When I display the form modally, it works. When I display it non-modally, nothing displays.



                  I imagine that displaying a form non-modally, where execution continues, takes everything out of scope as the unit test ends. That means the form does not display. Or, perhaps the unit testing code knows it can't display anything unless execution stops and never even displays it? Not sure. So far, though, I have been able to make several different forms pop up inside unit test methods.



                  (I am sure this is not a very good answer, but I don't have the points to simply comment yet...)



                  EDIT: I have run into modal forms that also do not display, and I cannot figure out why. I can debug the test, and when it comes to the line where my form is being displayed with ShowDialog(), execution pauses but no form displays. I can even inspect the form in the debug window and see that its dimensions are correct and Visible = true -- still nothing. So, I'm stumped.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 13 '16 at 21:41

























                  answered Jan 13 '16 at 20:22









                  sutekh137

                  353214




                  353214
























                      up vote
                      0
                      down vote













                      I think you are trying to use the wrong tool for your problem... Dealing with GUI just for debug purpose can be frustrating...



                      Check out HypnoLog, an open source tool I developed to help me debug image processing application I been writing using C# and EmguCV.



                      With HypnoLog you can see the images as output in your browser, which acting as output log.



                      In your case you should check HypnoLog-CSharp, and there is already a simple visualizer for images. Your code will look something like this:



                      HL.log(debugImage, "image");


                      note, debugImage should be image encoded in base64, see ImageVisualizer for more information.






                      share|improve this answer

























                        up vote
                        0
                        down vote













                        I think you are trying to use the wrong tool for your problem... Dealing with GUI just for debug purpose can be frustrating...



                        Check out HypnoLog, an open source tool I developed to help me debug image processing application I been writing using C# and EmguCV.



                        With HypnoLog you can see the images as output in your browser, which acting as output log.



                        In your case you should check HypnoLog-CSharp, and there is already a simple visualizer for images. Your code will look something like this:



                        HL.log(debugImage, "image");


                        note, debugImage should be image encoded in base64, see ImageVisualizer for more information.






                        share|improve this answer























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          I think you are trying to use the wrong tool for your problem... Dealing with GUI just for debug purpose can be frustrating...



                          Check out HypnoLog, an open source tool I developed to help me debug image processing application I been writing using C# and EmguCV.



                          With HypnoLog you can see the images as output in your browser, which acting as output log.



                          In your case you should check HypnoLog-CSharp, and there is already a simple visualizer for images. Your code will look something like this:



                          HL.log(debugImage, "image");


                          note, debugImage should be image encoded in base64, see ImageVisualizer for more information.






                          share|improve this answer












                          I think you are trying to use the wrong tool for your problem... Dealing with GUI just for debug purpose can be frustrating...



                          Check out HypnoLog, an open source tool I developed to help me debug image processing application I been writing using C# and EmguCV.



                          With HypnoLog you can see the images as output in your browser, which acting as output log.



                          In your case you should check HypnoLog-CSharp, and there is already a simple visualizer for images. Your code will look something like this:



                          HL.log(debugImage, "image");


                          note, debugImage should be image encoded in base64, see ImageVisualizer for more information.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 8 at 23:57









                          Simon Ldj

                          111




                          111






























                               

                              draft saved


                              draft discarded



















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f34467064%2fis-it-possible-to-display-a-windows-form-from-within-unit-tests%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Schultheiß

                              Verwaltungsgliederung Dänemarks

                              Liste der Kulturdenkmale in Wilsdruff