views:

49

answers:

1

I'm writing an NUnit TextFixture for portions of a Windows Forms application. Some of the classes in the file are derived from UI component classes, like so:

[TestFixture]
public class MainFormTest : PersistenceTestBase // Base class here is not a form
{
    class TestMainForm : MainForm // MainForm inherits from Form
    {
        public new String SomeMethod()
        {
            // Some MainForm private method overridden to expose it to my test fixture
        }
    }

    private TestMainForm mainForm;

    [TestFixtureSetUp]
    public void TestFixtureSetUp()
    {
        mainForm = new TestMainForm();
    }

    [Test]
    public void TestMainFormDoesXYZ()
    {
        // Perform unit testing...
    }
}

However, an annoyance I have encountered is that since the classes inherit from UI component classes, Windows opens up the designer window when I double-click my unit test file in the Solution Explorer. Which, since it's not a "real" UI element (but a test class), it displays as a broken UI (depending on how I arrange the file, messages like "The designer could not be shown for this file because none of the classes within it can be designed" are shown). Is there a way to supress this behavior, or will I always have to right-click this file and "View Code"?

+5  A: 

Right click, select "Open With...", select the editor you want and click "Set as Default".

Do you really need your test classes to pretend they're something they're not though? That doesn't sound like a terribly good idea to me.

Jon Skeet
Nice! Actually the test classes *extend* the basic controls (as internal classes to the unit test), but I never want to edit those as forms (only the base classes). So they really act as the real forms within the test. The reason for this is to basically let my UnitTest control the Form as a user would and perhaps access some internal bits needed for testing. I've found UnitTesting forms problematic outside of using some record/playback framework. Any other ideas for hands-off testing of Windows Forms?
Ogre Psalm33
Hehe, right after I hit "Add Comment" on that previous comment, I realized perhaps my final sentence deserves a Stack Overflow question of it's own (if one doesn't already exist). :-)
Ogre Psalm33
@Ogre: I hadn't noticed that the test fixture itself wasn't the class extending the form.
Jon Skeet