Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

A UserControl cannot be dragged-dropped onto a winform. Instead, I must compile the assembly add it to my toolbox, then I can drag it onto a Form.

Doing this toolbox approach just to test out a control and then "tweak" it repeatedly is quite cumbersome.

Right now, I plan to simply have this toolbox item pointing to a bin/debug assembly which will be repeatedly re-built. I imagine this will come with it's own set of problems.

So what is a good strategy for testing UserControls?

share|improve this question
    
If you add a winforms application project to the same solution, your user control will show up in the toolbox. –  Tamás Szelei Feb 7 '12 at 18:27
    
@Tamas Szelei - See the related question: stackoverflow.com/questions/9178582/… –  P.Brian.Mackey Feb 7 '12 at 18:33
    
I don't get it. So your problem is that you can't drag'n'drop from the solution explorer, only from the toolbox? –  Tamás Szelei Feb 7 '12 at 20:27
    
My problem is how to perform rapid application development and unit testing against a user control. –  P.Brian.Mackey Feb 7 '12 at 20:38
    
As I said, if you add another project and reference this one, you have what you want. It doesn't need to be done each time you change something (I think you don't even have to manually add it to the toolbox once you reference the project). –  Tamás Szelei Feb 7 '12 at 21:13

1 Answer 1

up vote 2 down vote accepted

In your comments, you state that you unit test your Windows forms by programmatically instantiating them and performing a visual inspection. I don't normally associate such testing with "unit testing," as unit testing is normally accomplished without any kind of user confirmation of the results; i.e. it is completely automated.

Regardless, if you simply want to instantiate a User Control programmatically, just add the User Control to a Windows form using code, and then show that form in the usual manner.

The necessary code for adding your User Control to the form will be automatically code-generated by Visual Studio if you drag the User Control onto the new form (the new code will be in the #region marked "Windows Forms Designer generated code" of the designer file). You can then copy-paste that code to an appropriate place, and execute it as part of your test.

share|improve this answer
    
You are correct. I am abusing MSTEST a little bit. I'm using it as a UI invoking tool to do some manual testing. I should have clarified because that is an unusual thing to do. –  P.Brian.Mackey Feb 9 '12 at 21:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.