Search code examples
c#visual-studioidenunitdesign-view

Is there a way to prevent Visual Studio 2008 from opening a file in design view by default?


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"?


Solution

  • 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.