<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Unit Testing User Interfaces (Updated!)</title><link>http://blogs.msdn.com/josealmeida/archive/2004/06/15/UnitTestingUserInterfaces.aspx</link><description>Usually one of the major difficulties a developer faces when writing unit tests is how to write test code for User Interfaces. This is particularly important when we're doing Test-Driven Development.</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Unit testing session</title><link>http://blogs.msdn.com/josealmeida/archive/2004/06/15/UnitTestingUserInterfaces.aspx#173148</link><pubDate>Mon, 05 Jul 2004 14:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:173148</guid><dc:creator>JoseAlmeida's Blog</dc:creator><description /></item><item><title>Unit testing session</title><link>http://blogs.msdn.com/josealmeida/archive/2004/06/15/UnitTestingUserInterfaces.aspx#173506</link><pubDate>Tue, 06 Jul 2004 03:10:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:173506</guid><dc:creator>JoseAlmeida's Blog</dc:creator><description /></item><item><title>re: Unit Testing User Interfaces</title><link>http://blogs.msdn.com/josealmeida/archive/2004/06/15/UnitTestingUserInterfaces.aspx#177959</link><pubDate>Fri, 09 Jul 2004 11:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:177959</guid><dc:creator>sog1</dc:creator><description>Can you list complete code for the tester class including imports, references etc.?&lt;br&gt;&lt;br&gt;The NunitForms documentation is very lacking.&lt;br&gt;&lt;br&gt;Thanks</description></item><item><title>re: Unit Testing User Interfaces</title><link>http://blogs.msdn.com/josealmeida/archive/2004/06/15/UnitTestingUserInterfaces.aspx#181731</link><pubDate>Tue, 13 Jul 2004 21:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:181731</guid><dc:creator>José Almeida</dc:creator><description>Sure.&lt;br&gt;&lt;br&gt;First reference the nunit.framework and NUnitForms assemblies (nunit.framework.dll and NUnitForms.dll).&lt;br&gt;&lt;br&gt;Then you just need to add the following uses:&lt;br&gt;&lt;br&gt;using NUnit.Framework;&lt;br&gt;using NUnit.Extensions.Forms;&lt;br&gt;&lt;br&gt;and the namespace of your class library that has all the forms.&lt;br&gt;&lt;br&gt;After that it's just as I described above. NUnitForms doesn't have wrapper objects for all the controls (yet), but the ones that are available are the most common and should be enough for most situations.&lt;br&gt;&lt;br&gt;Anyway, here's a complete listing for a sample test class that uses NUnitForms:&lt;br&gt;using System;&lt;br&gt;using NUnit.Framework;&lt;br&gt;using NUnit.Extensions.Forms;&lt;br&gt;using DemoWinFormsApp;&lt;br&gt;&lt;br&gt;namespace NUnitFormsTester&lt;br&gt;{&lt;br&gt;	[TestFixture]&lt;br&gt;	public class NUnitFormsTest&lt;br&gt;	{&lt;br&gt;		MyForm form;&lt;br&gt;&lt;br&gt;		public NUnitFormsTest()&lt;br&gt;		{&lt;br&gt;		}&lt;br&gt;&lt;br&gt;		[SetUp]&lt;br&gt;		public void SetUp() &lt;br&gt;		{&lt;br&gt;			form = new MyForm();&lt;br&gt;			form.Show();&lt;br&gt;		}&lt;br&gt;&lt;br&gt;		[Test]&lt;br&gt;		public void Test()&lt;br&gt;		{&lt;br&gt;&lt;br&gt;			TextBoxTester MyTextBox = new TextBoxTester(&amp;quot;MyTextBox&amp;quot;);&lt;br&gt;			ButtonTester MyButton = new ButtonTester(&amp;quot;MyButton&amp;quot;);&lt;br&gt;			LabelTester MyLabel = new LabelTester(&amp;quot;MyLabel&amp;quot;);&lt;br&gt;&lt;br&gt;			MyTextBox.Enter(&amp;quot;NUnitForms Test&amp;quot;);&lt;br&gt;			MyButton.Click();&lt;br&gt;			Assertion.AssertEquals(MyLabel.Text, &amp;quot;NUnitForms Test&amp;quot;);&lt;br&gt;		}&lt;br&gt;	}&lt;br&gt;}&lt;br&gt;&lt;br&gt;hope it helps!&lt;br&gt;Cheers!</description></item><item><title>re: Unit Testing User Interfaces</title><link>http://blogs.msdn.com/josealmeida/archive/2004/06/15/UnitTestingUserInterfaces.aspx#183779</link><pubDate>Thu, 15 Jul 2004 15:53:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:183779</guid><dc:creator>Hans M. Rupp</dc:creator><description>Hallo I am trying out NUnitForms and I cannot get it working. I always get a NoSuchControlException:&lt;br&gt;&lt;br&gt;NUnitFormsTest.GUITest.Test1 : NUnit.Extensions.Forms.NoSuchControlException : TextBox&lt;br&gt;&lt;br&gt;I cannot figure out what's wrong :-( Looking at the documentation I thought that the controls are accessed by their name.&lt;br&gt;&lt;br&gt;The program to be tested:&lt;br&gt;---------------------------------------------------------------&lt;br&gt;using System;&lt;br&gt;using System.Drawing;&lt;br&gt;using System.Collections;&lt;br&gt;using System.ComponentModel;&lt;br&gt;using System.Windows.Forms;&lt;br&gt;using System.Data;&lt;br&gt;&lt;br&gt;namespace NUnitFormsTest&lt;br&gt;{&lt;br&gt;	&lt;br&gt;	public class Form1 : System.Windows.Forms.Form&lt;br&gt;	{&lt;br&gt;		private System.Windows.Forms.TextBox TextBox;&lt;br&gt;	&lt;br&gt;		private System.ComponentModel.Container components = null;&lt;br&gt;&lt;br&gt;		public Form1()&lt;br&gt;		{&lt;br&gt;			&lt;br&gt;			InitializeComponent();&lt;br&gt;&lt;br&gt;			&lt;br&gt;		}&lt;br&gt;&lt;br&gt;		&lt;br&gt;		protected override void Dispose( bool disposing )&lt;br&gt;		{&lt;br&gt;			if( disposing )&lt;br&gt;			{&lt;br&gt;				if (components != null) &lt;br&gt;				{&lt;br&gt;					components.Dispose();&lt;br&gt;				}&lt;br&gt;			}&lt;br&gt;			base.Dispose( disposing );&lt;br&gt;		}&lt;br&gt;&lt;br&gt;		#region Windows Form Designer generated code&lt;br&gt;		&lt;br&gt;		private void InitializeComponent()&lt;br&gt;		{&lt;br&gt;			this.TextBox = new System.Windows.Forms.TextBox();&lt;br&gt;			this.SuspendLayout();&lt;br&gt;			// &lt;br&gt;			// TextBox&lt;br&gt;			// &lt;br&gt;			this.TextBox.Location = new System.Drawing.Point(24, 40);&lt;br&gt;			this.TextBox.Name = &amp;quot;TextBox&amp;quot;;&lt;br&gt;			this.TextBox.Size = new System.Drawing.Size(240, 20);&lt;br&gt;			this.TextBox.TabIndex = 0;&lt;br&gt;			this.TextBox.Text = &amp;quot;&amp;quot;;&lt;br&gt;			// &lt;br&gt;			// Form1&lt;br&gt;			// &lt;br&gt;			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);&lt;br&gt;			this.ClientSize = new System.Drawing.Size(292, 273);&lt;br&gt;			this.Controls.AddRange(new System.Windows.Forms.Control[] {&lt;br&gt;																		  this.TextBox});&lt;br&gt;			this.Name = &amp;quot;Form1&amp;quot;;&lt;br&gt;			this.Text = &amp;quot;Form1&amp;quot;;&lt;br&gt;			this.ResumeLayout(false);&lt;br&gt;&lt;br&gt;		}&lt;br&gt;		#endregion&lt;br&gt;&lt;br&gt;		&lt;br&gt;		[STAThread]&lt;br&gt;		static void Main() &lt;br&gt;		{&lt;br&gt;			Application.Run(new Form1());&lt;br&gt;		}&lt;br&gt;&lt;br&gt;		&lt;br&gt;	}&lt;br&gt;}&lt;br&gt;&lt;br&gt;----------------------------------------------------------------------------------&lt;br&gt;The test:&lt;br&gt;&lt;br&gt;using System;&lt;br&gt;using NUnit.Framework;&lt;br&gt;using NUnit.Extensions.Forms;&lt;br&gt;&lt;br&gt;namespace NUnitFormsTest&lt;br&gt;{&lt;br&gt;	&lt;br&gt;	[TestFixture]&lt;br&gt;	public class GUITest : Assertion {&lt;br&gt;		private Form1 form;&lt;br&gt;&lt;br&gt;		public GUITest() {	&lt;br&gt;		}&lt;br&gt;&lt;br&gt;		[SetUp]&lt;br&gt;		public void SetUp() {&lt;br&gt;			form = new Form1();&lt;br&gt;			form.Show();&lt;br&gt;		}&lt;br&gt;		&lt;br&gt;		[Test]&lt;br&gt;		public void Test1() {&lt;br&gt;			&lt;br&gt;		                TextBoxTester textBox = new TextBoxTester(&amp;quot;TextBox&amp;quot;);&lt;br&gt;			textBox.Enter(&amp;quot;Test&amp;quot;);&lt;br&gt;			AssertEquals(&amp;quot;Test&amp;quot;, textBox.Text);&lt;br&gt;		}&lt;br&gt;	}&lt;br&gt;}&lt;br&gt;&lt;br&gt;Many thanks,&lt;br&gt;&lt;br&gt;Hans&lt;br&gt;&lt;br&gt;&lt;br&gt;</description></item><item><title>re: Unit Testing User Interfaces</title><link>http://blogs.msdn.com/josealmeida/archive/2004/06/15/UnitTestingUserInterfaces.aspx#207874</link><pubDate>Wed, 04 Aug 2004 20:53:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:207874</guid><dc:creator>Robert Livermore</dc:creator><description>Han,&lt;br&gt;&lt;br&gt;I have a similar problems with NUNIT. With no solution, yet. In my situation, I have a UI button click that eventually makes an asynchronous SOAP request/response. Hence the SOAP request/response are done an a different thread of execution. In order for the response to repopulate the control requires the response to be copied back to the user's thread. I think this is done by Window's messaging. In order for a form to listen (hook or subclass) into the windows' messaging it must &amp;quot;start&amp;quot; the application by executing &amp;quot;System.Windows.Forms.Application.Run()&amp;quot;.&lt;br&gt;&lt;br&gt;The &amp;quot;Application.Run&amp;quot; when executed is blocked. (Because it is now listening to window's messages).  I do not have any threads left to run the Nunit test. I could start a new thread within the nunit test to run the button click, but the information will not be copied back to the proper thread or I have reentrancy problems.&lt;br&gt;&lt;br&gt;I think there needs to be a change in the NUNIT framework. NUNIT should support another mode. This mode after loading the test assembly into an application domain, should start a thread and execute the &amp;quot;System.Windows.Forms.Application.Run()&amp;quot;. When a test is executed, NUnit should add the delegate to message queue (see the BeginInvoke about queuing on the thread that the control's underlying handle was created). I think this should execute a button click the same way a mouse click would.&lt;br&gt;&lt;br&gt;Robert Livermore  B.Sc, MCP, MCSD, MCSE+I, MCDBA &lt;br&gt;Senior Developer&lt;br&gt;Cetaris  &lt;br&gt;www.cetaris.com  &lt;br&gt;</description></item><item><title>NUnitForms</title><link>http://blogs.msdn.com/josealmeida/archive/2004/06/15/UnitTestingUserInterfaces.aspx#218740</link><pubDate>Mon, 23 Aug 2004 09:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:218740</guid><dc:creator>wildhope</dc:creator><description>Ping Back来自：blog.csdn.net</description></item></channel></rss>