Use Win Form in a VS Team Test library


This may be common knowledge, but I just discovered it. Test projects in VS Team Test are class libraries. Normally you write tests like a console app, with no UI. You just test api results and test results with the Assert class – nice, simple and works great. However, a lot of times, I like testing and modeling work in progress with a UI form. I just add a bunch of buttons each with some code I am testing. Works good for me as it is visually organized and double-click to see code-behind is just so natural. I use a form as a kind of scratch pad for ideas and small tests on logic. Not as a replacement for unit tests, but as dev tool. Also a nice way to create various samples for using your library. Nuf said. Anyway, I thought it would be nice to pop a form up as one of the unit tests and work with it. Kinda like a manual test. This is nice because you don’t need to create yet another Project just to create Windows Form test harness and junk up your dir structure. So to keep your forms and helper class in the Test project library. Here is sort summary:

  1. Create a Windows form in the project as normal. This will add the System.Windows.Forms reference for you.
  2. Open your blank form and add buttons and logic as needed.
  3. Add a new "Unit Test" to the project and pick a good name.
  4. Add a [TestMethod] method to the class and call it something like TestForm1. This is the unit test method that will be called via testing framework. Add code to open your form in this method; something like:


void TestMethod1()







//Form1 f1 = new Form1();



    You can either use the Application.Run method or just use ShowDialog() as shown.

  1. Run your "TestForm1" unit test. It will bring up your form. You can click and test your form as needed. All Console.WriteLine() output will be collected into the Test Result for the unit test. You will see it only after you close the form. Any uncaught exception will also be posted in the test output record. This makes it nice and tidy.
  2. When you close your form, your other selected tests (if any) will continue. Perfect!

Add as many forms or classes as you need. Using this method, you can collect all your samples into the same test project and distro a single library along with your other project you are testing.

This entry was posted in Uncategorized. Bookmark the permalink.

3 Responses to Use Win Form in a VS Team Test library

  1. Unknown says: Asus f3 Battery Toshiba pa3594u-1brs Battery Toshiba pa3593u-1bas Battery Toshiba pabas111 Battery Dell xps m1530 Battery Hp tx2000 Battery Hp pavilion tx1000 Battery Dell xps m1730 Battery Hp pavilion dv6 Battery Toshiba pa3395u-1brs Battery Toshiba pa3421u-1brs Battery Toshiba pa3451u-1brs Battery Toshiba pa3399u-1brs Battery Toshiba pa3399u-2bas Battery Toshiba satellite a100 Battery Toshiba satellite m40 Battery Toshiba satellite m45 Battery Toshiba satellite m55 Battery Toshiba pa3356u Battery Toshiba pa3356u-1bas Battery Toshiba pa3356u-1brs Battery Toshiba pa3356u-2brs Battery Toshiba pa3456u-1brs Battery Toshiba portege m500 Battery Toshiba pa3451u Battery Toshiba pabas067 Battery Toshiba pa3465u-1brs Battery Toshiba pa3534u-1brs Battery Toshiba pa3533u-1bas Battery Toshiba satellite a205 Battery Toshiba pa3534u-1bas Battery Uniwill 255-3s4400-g1l1 Battery Uniwill un255 Battery

  2. Unknown says: toshiba 4000 battery toshiba pa3062u-1bar battery toshiba tecra 8200 battery toshiba pa3128u battery toshiba pa3191u battery toshiba portege 4000 battery toshiba portege m200 battery toshiba portege m205 battery toshiba portege m400 battery toshiba pa3128u grey battery toshiba pa3191u grey battery toshiba te2000 grey battery toshiba pa3209u battery toshiba satellite 1100 battery toshiba satellite 1110 battery toshiba pa3210u battery toshiba satellite 1115 battery toshiba pa3399u-1bas battery toshiba satellite a100 battery toshiba satellite m100 battery toshiba pa3399u-1bas battery toshiba satellite a100 battery toshiba satellite a105 battery toshiba satellite a80 battery toshiba satellite m100 battery toshiba satellite m105 battery toshiba satellite m110 battery toshiba satellite m115 battery toshiba satellite m40 battery toshiba satellite m45 battery toshiba satellite m50 battery toshiba satellite m55 battery toshiba pa3356u battery toshiba a50 battery toshiba a55 battery toshiba portege m300 battery toshiba portege m500 battery toshiba portege s100 battery toshiba qosmio f20 battery toshiba qosmio f25 battery toshiba satellite a50 battery toshiba satellite a55 battery toshiba pa3356u-1bas battery toshiba satellite a50 battery toshiba satellite a55 battery

  3. Unknown says: dell latitude d531 battery dell precision m65 battery dell d820 battery dell inspiron 6000 battery dell inspiron 9200 battery dell inspiron 9300 battery dell inspiron 9400 battery dell e1705 battery dell inspiron 1520 battery dell inspiron 1720 battery dell vostro 1500 battery dell vostro 1700 battery dell 0xr693 battery dell 312-0625 battery dell 312-0633 battery dell gw240 battery dell hp297 battery dell rn873 battery dell xr693 battery dell inspiron 1525 battery dell inspiron 1526 battery dell m1210 battery dell nf343 battery dell 1210 battery dell cg036 battery dell d044h battery dell w953g battery dell 312-0831 battery dell inspiron 910 battery dell inspiron mini 9 battery dell xd187 battery dell inspiron 1300 battery dell inspiron b120 battery dell inspiron b130 battery gateway 12msbg battery gateway 4s2p battery gateway 8msb battery gateway 8msbg battery gateway s62044l battery gateway m320 battery gateway m325 battery gateway 4000 battery gateway s62066l battery gateway m680 battery gateway m360 battery gateway m460 battery gateway s62066l battery gateway bat0016 battery gateway m1200 battery gateway m1300 battery gateway m500 battery gateway m505 battery gateway btp-68b3 battery gateway btp-51b3 battery hp hstnn-db11 battery

Comments are closed.