Solved

How can we use Visual Studio Testing to unit test a form

Posted on 2008-06-11
12
237 Views
Last Modified: 2013-11-26
I'm trying to set up a unit test to simulate a user entering information onto a form created in VB.NET.  I see a load of examples for testing classes on the web, but nothing that goes through testing a form which is compromised of 95% subs - not functions.  I know I can set it up to run the Form Load events, etc - but I cannot simulate the addition of test in many of my field since we use many user controls and the actual text properties for controls within the users controls are Read Only as they should be.  

I'm basically looking for a site with information on how to test a class that inherits from Form.  I know this will be hard to actually explain in this forum, but a simple link to a good site would be great.  Thanks!
0
Comment
Question by:CyprexxDev
  • 4
  • 3
  • 2
  • +1
12 Comments
 
LVL 12

Expert Comment

by:renjurdevan
ID: 21766308
please go through the link below

http://www.nunit.com/index.php
0
 
LVL 1

Author Comment

by:CyprexxDev
ID: 21769916
That site has a testing add-in, but does not explain how to test a Windows Form Application.  

More specifically, the application we're developing is composed of numerous forms.  If I try to test certain routines in one form, often times there is code that will open another form based on user input.  Of course, during a test I don't want these other forms opening since it stops the test.  I'm just not sure at all that anything in the test environment was developed for forms as I see nothing indicating this online or in Microsoft's documentation.  Every example I've found is for testing functions within a  basic class.
0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 21775937
0
 
LVL 1

Author Comment

by:CyprexxDev
ID: 21874896
As I said in my previous reply, this site gives examples on a Class, not a Form.  The second paragraph starts off saying:

Suppose we are writing a bank application and we have a basic domain class  Account.

I want examples on how to test a form, not a class.  A form has button click events, etc...  that these examples do not have.
0
 
LVL 24

Accepted Solution

by:
Jeff Certain earned 500 total points
ID: 21879663
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 14

Expert Comment

by:jake072
ID: 21883576
Nothing will replace or can replace having a few people still down and hammer on it.

Just my opinion, but trust me, it works.  Give it to a buddy and ask him to break it.  He will.

Jake
0
 
LVL 1

Author Comment

by:CyprexxDev
ID: 21886530
I'll take a further look at that post Chaosian.  Thanks for the link - it seems to answer the question.

Jake, I agree with you completely.  We would, however, like to use the testing functionality provided by VS to at least set up a regression testing scenario that can be run after each release build.  Our application is gigantic - it would take hours to test each release without some automated script.  I'd like to at least eliminate 75% of this work.
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 21886707
Gald to help.

Jake -- that's why I had a PM who pressed buttons at random until something broke...
0
 
LVL 14

Expert Comment

by:jake072
ID: 21887060
- I know what you guys mean.  I just don't understand (I could just be an idiot) the advantages that a scripted testing system would provide.  So you script it to do something, how do you know that it worked, or are you just looking for exceptions, rather than behavior?  For instance, you could have a method that does something in a DB.  It might not throw an exception, but it might not work properly either...

Am I missing something?  Just curious!

Jake
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 21887212
Unit testing provides a few benefits. (And yes, database testing is a challenge).

First, it lets you know that the piece of code you're testing works properly. this is done at a fine-grained level, and allows you to test boundaries and exceptions. Any bug that is found in these functions is really two bugs -- one in the code and one in the test suite.

Second, when you're done with a piece of code, you're *done*. Move on. Check it in. It's complete, and you know you're not going to have to come back to it. The unit tests provide a regression test suite, so that you can be assured that your later code hasn't broken stuff you thought you were done with. (Or, you know it before it goes out the door).

Third, you can adopt development methodologies that test the code as it is written (TDD, BDD, etc). This gives you the ability to correct your code while the context is still fresh in your mind. You can also build your unit tests into source control and continuous integration, so you know immediately that your code base is always buildable and correct (or as correct as your test suite).
0
 
LVL 1

Author Comment

by:CyprexxDev
ID: 21887869
Exactly...  We won't use unit testing to make sure that the forms will update the database correctly from the start (though I would like to get to this point).  There are things, however, that it's very nice for.  For instance, when we make a change in the database, such as changing the name of a field, we want to make sure all Stored Procedures are updates with that new field name (which is impossible on the DB end as far as I know).  What we can do, however, is run a unit test on the application side to make sure that all previous forms that used those SPs will open properly, that all dialogues will still be displayed as intended, etc.  The moment a form opens that calls an SP where that field name was changed, there will be an exception on the applciation side.  Due to the fact that we have 100s of forms, we don't want to have someone go in and make sure they all still work after every change.

This is obviously a glaring example of how this would benefit, but there are lesser obvious circumstances.  Anyway, I've been busy all day and haven't had time to look at the link.  I'm going to assign points based on the fact that this page at least looks like what I need based on the question I asked.  If it's not, it's still the first reply that directly answers the question.  Thanks Chaosian!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now