Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2008

Tip: Looking for answers? Try searching our database.

Trying to nunit test a form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David Thielen - 01 Jan 2008 23:33 GMT
Hi;

I have some simple nunit tests for my forms. When I run nunit from Visual
Studio they run fine. But when I use the nunit command line app to tun it I
get the following:
21) net.windward.autotag.controls.TestTagEditor.TestSet :
System.Threading.ThreadStateException : ActiveX control
'8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the
current thread is not in a single-threaded apartment.
  at System.Windows.Forms.WebBrowserBase..ctor(String clsidString)
  at System.Windows.Forms.WebBrowser..ctor()
  at net.windward.autotag.controls.ImportControl.InitializeComponent() in
C:\src\kahuna\AutoTag\AutoTagCore\net\windward\autotag\controls\ImportControl.Designer.cs:line 34
  at net.windward.autotag.controls.ImportControl..ctor() in
C:\src\kahuna\AutoTag\AutoTagCore\net\windward\autotag\controls\ImportControl.cs:line 23
  at net.windward.autotag.controls.TagEditor.InitializeComponent() in
C:\src\kahuna\AutoTag\AutoTagCore\net\windward\autotag\controls\TagEditor.Designer.cs:line 557
  at net.windward.autotag.controls.TagEditor..ctor(IFramework app,
TagPosition tagPos) in
C:\src\kahuna\AutoTag\AutoTagCore\net\windward\autotag\controls\TagEditor.cs:line 134
  at net.windward.autotag.controls.TestTagEditor.TestSet() in
C:\src\kahuna\AutoTag\TestCore\net\windward\autotag\controls\TestTagEditor.cs:line 266

What's going on and what do I need to do to let these tests run from the
command line?

Signature

thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm

Linda Liu[MSFT] - 02 Jan 2008 03:54 GMT
Hi Dave,

Could you tell me what command line you are using to run your unit test?

From the exception stack you showed, it seems that you use a WebBrowser on
the form to be tested.

I create a Windows Application project named 'WindowsApplicationForTest'
and add a WebBrowser control on the form. I add a public method called
'Navigate' in the form to navigate a URL using the WebBrowser. Then I
create a unit test for the public method 'Navigate'.

The following is the sample code in my test.

// Windows Application project

public partial class Form1 : Form
{
   ...
   public bool Navigate()
       {
           this.webBrowser1.Navigate("http://www.google.com");
           return true;
       }
}

// Test project
<TestClass()> _
Public Class Form1Test
   ...
   <TestMethod()> _
   Public Sub NavigateTest()
       Dim target As Form1 = New Form1

       Dim expected As Boolean
       Dim actual As Boolean

       expected = True
       actual = target.Navigate

       Assert.AreEqual(expected, actual,
"WindowsApplicationForTest.Form1.Navigate did not return the expected
value.")

   End Sub
End Class

Then I double click the 'WindowsApplicationForTest.vsmdi' under the
'Solution Item' node in the Solution Explorer and create a new test list
named 'TestList1' under the 'Lists for Tests' node. Select the 'All Loaded
Tests' node and drag the 'NavigateTest' on the right panel onto the newly
created Test List 'TestList1'.

From the VS2005 Command Prompt, swith to the Solution folder and type the
following command:

MSTest /testmetadata:TestProject1.vsmdi /testlist:TestList1

The result is that the unit test is run properly without any exception.

If there's any difference between your test and mine, please let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
David Thielen - 02 Jan 2008 14:55 GMT
I am using nunit-console.exe in NUnit 2.2.7. My code is:

    [TestFixture]
    public class TestTagEditor
    {

...

        [Test]
        public void TestDefaultReturn()
        {

            // new tag
            using (TagEditor dlg = new TagEditor(CreateFramework(), new
TagPosition(null, new BaseTag[0], null)))
            {
                Assert.IsNotNull(dlg);
                Assert.AreEqual("<wr:out/>", dlg.TagPosReturn.Tag.toText());
            }

            // existing tag
            using (TagEditor dlg = new TagEditor(CreateFramework(), new
TagPosition(BaseTag.factory("<wr:forEach var=\"dave\" select=\"/root\">", 0,
false), new BaseTag[0], null)))
            {
                Assert.IsNotNull(dlg);
                Assert.AreEqual("<wr:forEach select=\"/root\" var=\"dave\">",
dlg.TagPosReturn.Tag.toText());
            }
        }
}

Signature

thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm

> Hi Dave,
>
[quoted text clipped - 81 lines]
>  
> This posting is provided "AS IS" with no warranties, and confers no rights.
Linda Liu[MSFT] - 03 Jan 2008 10:23 GMT
Hi Dave,

Thank you for your reply!

I do more research on the NUnit and find that you should use the
configuration file to ensure that NUnit uses STA appartment state to run
your tests.

For more information on how to do this, please refer to the following
article:

http://watin.sourceforge.net/apartmentstateinfo.html#nunit

Hope this helps.

Sincerely,
Linda Liu
Microsoft Online Community Support
David Thielen - 03 Jan 2008 23:05 GMT
How on earth do you guys know all these answers??????????????

Works great - thank you

Signature

thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm

> Hi Dave,
>
[quoted text clipped - 14 lines]
> Linda Liu
> Microsoft Online Community Support

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.