473,805 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unit tests and Messagebox

I'm writing some unit tests, to make sure that my windows forms code
works properly after refactoring, and I've bumped into a problem -
Messagebox.show .

There are a couple of places where my code pops up a messagebox to
inform the user of what's going on, and if this happens during a unit
test then it requires the user to click on the button before it can
finish the test. Which isn't much use for, say, unattended automatic
testing.

Is there any way to intercept a Messagebox call and fake it being
clicked? Or is there some other way that I should approach this?

Cheers,

Andy D

Nov 12 '06 #1
7 7821
Hello Andrew,

Have u tried to find that window and programatically push the button?

ADI'm writing some unit tests, to make sure that my windows forms code
ADworks properly after refactoring, and I've bumped into a problem -
ADMessagebox.sh ow.
AD>
ADThere are a couple of places where my code pops up a messagebox to
ADinform the user of what's going on, and if this happens during a
ADunit test then it requires the user to click on the button before it
ADcan finish the test. Which isn't much use for, say, unattended
ADautomatic testing.
AD>
ADIs there any way to intercept a Messagebox call and fake it being
ADclicked? Or is there some other way that I should approach this?
AD>
ADCheers,
AD>
ADAndy D
AD>
---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Nov 12 '06 #2
Hi Andrew,

Check out NUnitForms.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Andrew Ducker" <an****@ducker. org.ukwrote in message
news:11******** *************@h 54g2000cwb.goog legroups.com...
I'm writing some unit tests, to make sure that my windows forms code
works properly after refactoring, and I've bumped into a problem -
Messagebox.show .

There are a couple of places where my code pops up a messagebox to
inform the user of what's going on, and if this happens during a unit
test then it requires the user to click on the button before it can
finish the test. Which isn't much use for, say, unattended automatic
testing.

Is there any way to intercept a Messagebox call and fake it being
clicked? Or is there some other way that I should approach this?

Cheers,

Andy D
Nov 12 '06 #3
Andrew,

I would just make my own new form as a messagebox.

Cor

"Andrew Ducker" <an****@ducker. org.ukschreef in bericht
news:11******** *************@h 54g2000cwb.goog legroups.com...
I'm writing some unit tests, to make sure that my windows forms code
works properly after refactoring, and I've bumped into a problem -
Messagebox.show .

There are a couple of places where my code pops up a messagebox to
inform the user of what's going on, and if this happens during a unit
test then it requires the user to click on the button before it can
finish the test. Which isn't much use for, say, unattended automatic
testing.

Is there any way to intercept a Messagebox call and fake it being
clicked? Or is there some other way that I should approach this?

Cheers,

Andy D

Nov 13 '06 #4
"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:uc******** ******@TK2MSFTN GP02.phx.gbl...
Andrew,

I would just make my own new form as a messagebox.
Change the app to suit the test? Shouldn't it be the other way around?

Michael
Nov 13 '06 #5
How about a debug/unit test log flag say isLogMessageBox that writes to
a log
in debug/unit test mode and pops up a message box in release mode. Me
thinks
that if you define the bool flag in the file as a const (constants are
not
versionable, must be recompiled to reflect changes), the compiler will
optimize
the code and remove the if/then logic in release mode. I have not tested
this. To
avoid mistakes, you might want to wrap the conditional call to
MessageBox.Show () into a method DebugMessageBox .Show() and replace the
appropriate calls to MessageBox.Show () with a call to the conditional
DebugTestMessag eBox.Show(). In release mode, set the flag
isLogMessageBox to
false and recompile.

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '06 #6
Try the unit test for Visual Studio Team Sysytem
http://msdn.microsoft.com/vstudio/teamsystem/tester/

pretty cool.

chanmm

"Andrew Ducker" <an****@ducker. org.ukwrote in message
news:11******** *************@h 54g2000cwb.goog legroups.com...
I'm writing some unit tests, to make sure that my windows forms code
works properly after refactoring, and I've bumped into a problem -
Messagebox.show .

There are a couple of places where my code pops up a messagebox to
inform the user of what's going on, and if this happens during a unit
test then it requires the user to click on the button before it can
finish the test. Which isn't much use for, say, unattended automatic
testing.

Is there any way to intercept a Messagebox call and fake it being
clicked? Or is there some other way that I should approach this?

Cheers,

Andy D

Nov 13 '06 #7
On Nov 12, 8:12 pm, "Miha Markic [MVP C#]" <miha at rthand comwrote:
Check out NUnitForms.
Cheers for that - the ExpectedModal isn't quite perfect, but it does
near enough what I want that I'm no longer stuck.

Cheers!

Andy

Nov 14 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3692
by: Tom Verbeure | last post by:
Hello All, so I'm now convinced that unit testing is really the way to go and I want to add it to an existing project. The first thing that I find out, is that, well, it's hard work. Harder than writing the real functional code. My application manipulates graphs. I first write the skeleton in Python, then convert it to C++ for high performance (some graphs can have millions of nodes.)
14
2761
by: | last post by:
Hi! I'm looking for unit-testing tools for .NET. Somthing like Java has --> http://www.junit.org regards, gicio
72
5286
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: http://geosoft.no/development/unittesting.html Thanks.
6
2081
by: Michael Bray | last post by:
I've just inherited a fairly large project with multiple classes. The developer also wrote a huge number of unit tests (using NUnit) to validate that the classes work correctly. However, I don't think that the class itself should include unit tests, especially since it has to reference nunit.framework in order to compile/work, and I don't want to have to distribute the nunit.framework.dll with this class. So I created a new project,...
5
6531
by: shuisheng | last post by:
Dear All, I was told that unit test is a powerful tool for progamming. If I am writing a GUI code, is it possible to still using unit test? I have a little experience in using unittest++. But I can not work out a way to use it to test GUI code. Thanks a lot!
176
8481
by: nw | last post by:
Hi, I previously asked for suggestions on teaching testing in C++. Based on some of the replies I received I decided that best way to proceed would be to teach the students how they might write their own unit test framework, and then in a lab session see if I can get them to write their own. To give them an example I've created the following UTF class (with a simple test program following). I would welcome and suggestions on how anybody...
1
3445
by: Richard Lewis Haggard | last post by:
We're using VS05 and today the units tests have stopped working in our development environment. I'm sure that it is something really silly and simple but I'll be darned if I can figure out what it is. Here's a failure example: I created a simple little C# program called Test1. I added a new class that has a public method Sum, which does the brilliant function of adding two numbers together and returning the result. I added a unit test...
6
5692
by: Vyacheslav Maslov | last post by:
Hi all! I have many many many python unit test, which are used for testing some remote web service. The most important issue here is logging of test execution process and result. I strongly need following: 1. start/end timestamp for each test case (most important) 2. immediate report about exceptions (stacktrace) 3. it will be nice to use logging module for output
5
2844
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
I'm working in Visual Studio 2005 Team Edition for Software Developers I've used the wizard under the Test menu to create a bunch of unit tests. When I click "Test -Start Selected Test Project with Debugger" the tests run. I'd really like to create a WinForm User Interface to run the Unit Tests. The idea would be to give the user a list of Unit Tests in a table, and let the user select any combination of tests they like. The user then...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10369
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.