nunit / nunit3-vs-adapter

NUnit 3.0 Visual Studio test adapter for use under VS 2012 or later
https://nunit.org
MIT License
203 stars 105 forks source link

WinForms application is not rendered when debugging a test #628

Open miloszkukla opened 5 years ago

miloszkukla commented 5 years ago

Having a test like:

[Test]
public void Test()
{
    Application.Run(new Form());
}

works fine when run without debugging (form is visible) however when run with debugging, the form is not visible.

Possibly related to: https://github.com/nunit/nunit3-vs-adapter/pull/42 ?

jnm2 commented 5 years ago

Fyi @OsirisTerje, I reproduced this with the project I had open in VS (16.1)

christianjunk commented 4 years ago

The same for me:

christianjunk commented 4 years ago

According to this StackOverflow question I used the following workaround:

[Test, Apartment(ApartmentState.STA)]
[STAThread]
public void NameOfYourTest()
{
    using (var form = new NameOfYourForm())
    {
        form.Visible = true;
        form.Focus();
        Application.Run(form);
    }
}
OsirisTerje commented 4 years ago

@christianjunk Thanks! That makes sense! Do you mean it worked as it should with adding that? If so, it's a good workaround.

christianjunk commented 4 years ago

@christianjunk Thanks! That makes sense! Do you mean it worked as it should with adding that? If so, it's a good workaround.

@OsirisTerje This solution worked for me as expected. According to NUnit3 I have edited my answer and added the following line:

[Test, Apartment(ApartmentState.STA)]

https://github.com/nunit/docs/wiki/Apartment-Attribute