Unit testing a form...
We're trying to unit test the main form of our application.
Things like instantiating the form, checking for the default controls, invoking something that creates a new panel, checking for focus inside this new panel... all these things work great.
For testing navigation we're using the SendKeys class to send a Tab key press to the form from the unit test. This works fine when you run this test method independently.
However, when I run my entire test class, the test methods that are trying to test navigation using the SendKeys class are failing. When these tests are run by themselves they pass. When they are run with all the other tests they fail.
This was also happening with NUnit, and was one of the reasons I started exploring moving all our tests into VSTS. Any suggestions on how to get this to work properly?
Thanks.
[858 byte] By [
NewDawn] at [2008-1-28]
When you say "by itsself" do you mean running just that test from Test View/TEst Manager, or do you mean indipendantly of the test infrastructure?
Also, what do you mean by fail? Does it exception? Whats the error, whats the call stack?
Yours,
Dominic
Yes, I run the test from the Test View by itself (right-click this test, choose Run Selection) and this test will pass. If I run the test project from the IDE this test is the last one to get executed and it will fail.
By fail I just mean that the Assert fails so it flags the test as failing. It's not an error like an unhandled exception or anything.
Here is the error message, which is just the one Assert failing:
Assert.IsFalse failed. first control still has focus
And the Error Stack Trace just shows my method:
at JustWareSmartClientTests.frmMainTests.BannerTabForward()
I have a small app that duplicates the problem. It does not do it 100% of the time, but it does exhibit the problem around 5 out of 10 times running the entire test project from the IDE (using F5). One or both of the Tab tests will fail.
How can I get this zip file to you? I don't see a way to attach a file to the forum post here.
Right. Having spend sometime on this issue, it appears to be a similar problem that we experiance every day using our internal UI automation tools... Your moving too fast for the UI.
By taking the sample you provided, and introducing some Thread.Sleep()s between your Send Keys and actually validating the response, I got the tests to run reliably.
Whats happening is, that your validation code is being executed before the sendkey has completed. Additionally, you may need to do some Application.DoEvents to ensure that the events are processed also.
It's annoying, but it's one of those things that happens when you dont have an event based UI automation tool (Eg that uses IAccessible)