views:

77

answers:

4

I have a class that I want to test the DialogResult value for. To get that type I need to add a reference to System.Windows.Forms.

Is it bad practice to have this included in a test project?

+2  A: 

If you just need the enum definition for DialogResult I don't see any problem.

If you use that library to show UI's, that would be a bad thing from an automation point of view unless this automation suite is specifically designed to automatically test UI's (which I guess it isn't or you would already have the reference).

Eric J.
+2  A: 

Is what your testing inherently forms-related? If it's not, then the type itself shouldn't refer to DialogResult. If it is (and I suspect it is) then it's entirely reasonable for your tests to be forms-related too.

Jon Skeet
+1  A: 

It depends on your setup and the requirements of your test project(s), but as a general rule I would say it is not bad practice to do this; although in my experience, relatively uncommon practice.

Timothy Carter
+2  A: 

Include whatever you need for a unit test that can run without any human interaction, or the expectation that it is being observed.

If you wanted to see if something in the form showed up correctly then you are doing a functional test.

If you find that you have to do a lot of tests with forms then you may have too much business logic in your presentation layer (view layer) and you may want to move the business logic into a class that can be unit-tested separate from anything dealing with forms.

If you just need some enums or helper classes from Windows.Forms that doesn't have to do with actually creating a form then a unit test for that is fine.

James Black