4

Can I run Coded-UI Tests from Windows Froms Applications? Looking for a sample.

Thanks.

sqlnewbie
  • 857
  • 3
  • 16
  • 39
  • I don't understand well your question. Do you to create a form application that will execute your Coded-UI tests like MTM does, or do you want to test a form application? – chaliasos Feb 24 '12 at 10:41

4 Answers4

3

Of course you can - you can use mstest.exe command line application for running Coded UI Tests. You just need to write simple algorithm ensuring that correct parameters will be passed while launching mstest. For reference go here

Jakub Lenk
  • 31
  • 2
  • Quite indeed, I've faced such an issue months ago and ended up by using MSTest within my Windows Forms. If you want you can do it without MsTest but your TestContext variable ( which in my case is crucial ) won't get initialized thus killing all your data-driven tests. – ExtremeSwat May 06 '15 at 16:11
1

You should have a look at NUnitForms that is a extension to NUnit.

Your NUnit tests can open a window and interact with the controls. Your tests will automatically manipulate and verify the properties of the gui. NUnitForms takes care of cleaning up your forms between tests, detecting and handling modal dialog boxes, and verifying that your expectations for the test are fulfilled.

Reference here

Arion
  • 31,011
  • 10
  • 70
  • 88
1

see also

Unit testing Winforms UI

How to unit test winforms applications

Unit Test to verify that WinForms application doesn't load Assembly more than once

Basically you will better off separating your logic completely from the UI , making your UI as thin as possible, and testing the logic separately .

Community
  • 1
  • 1
Alex
  • 768
  • 1
  • 5
  • 13
0

You can find solution here for console application. You have to add additional references in order to work test in windows forms application or other project(I had to add reference to Microsoft.VisualStudio.TestTools.UITest.WindowsStoreUtility other than the listed refrences in the article). But as explained in this so answer it would be nice if you can use it in a project that is meant to use these assemblies.

Community
  • 1
  • 1
Ruwanka De Silva
  • 3,555
  • 6
  • 35
  • 51