473,395 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 7786
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.show.
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*********************@h54g2000cwb.googlegro ups.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*********************@h54g2000cwb.googlegro ups.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**************@TK2MSFTNGP02.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
DebugTestMessageBox.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*********************@h54g2000cwb.googlegro ups.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
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...
14
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
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: ...
6
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...
5
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...
176
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...
1
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...
6
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...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...

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.