473,322 Members | 1,409 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,322 software developers and data experts.

detecting running under UNIT TEST

Hi there,
I use Visual Studio 2005, c# projects...

I like the new unit test framework very much, it helps a lot mantaining and
growing up a project with the test driven paradigm, that's so good!

I'm looking for a way to detect if the program is running under the TEST
enviroment or running normally, let's say I need something like

#if TESTING

do some stuff...

#endif

or, I don't know what else... something that comes from the framework, I
don't want to set the TESTING by myself like DEBUG / TRACE in the compiler
configuration options...

any idea ?

Thanks, Davide.
Feb 13 '07 #1
3 5400
Ing. Davide Piras <da****@naxosoftware.comschrieb:
I'm looking for a way to detect if the program is running under the TEST
enviroment or running normally, let's say I need something like

#if TESTING

do some stuff...

#endif
You don't want to do that, because it completely defeats the purpose
of the tests. You'll introduce bugs that the testing framework will
not find.

Markus
Feb 13 '07 #2
Thank'you Markus, I think you are right, but probably there are some cases
where a swithc could help...

we develop a web application, for instance, we test the debug version in the
local machine then we deploy the release version on the remote server, the
remote server has SMTP on 127.0.0.1, the local machine has not

so, I would like to skip only the last code line (the mail sending action)
in the test case and still return true so the test is passed, the critical
code that could crash and should be tested is before!!!!

.... even if I'd a mail server on my computer, there is not point to send
email while testing !!

any idea ?

thanks, Davide.
Feb 13 '07 #3
PS

"Ing. Davide Piras" <da****@naxosoftware.comwrote in message
news:uF**************@TK2MSFTNGP06.phx.gbl...
Thank'you Markus, I think you are right, but probably there are some cases
where a swithc could help...

we develop a web application, for instance, we test the debug version in
the local machine then we deploy the release version on the remote server,
the remote server has SMTP on 127.0.0.1, the local machine has not

so, I would like to skip only the last code line (the mail sending action)
in the test case and still return true so the test is passed, the critical
code that could crash and should be tested is before!!!!

... even if I'd a mail server on my computer, there is not point to send
email while testing !!

any idea ?
The whole idea of testing is that making your code testable is what improves
the quality of your code. Without seeing the code I can only guess at what
is happening. You seem to be accessing some SMTP object that sends an email
and return true to indicate success. Make this SMTP object a parameter and
pass in a mock SMTP object that does nothing when SendMail() method is
called and returns true.

PS
Feb 14 '07 #4

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

Similar topics

11
by: Woojay Jeon | last post by:
OK, I tried a Google search on this Usenet group but couldn't find a solution, so I'm posting my question here (if there's a better archive than the one in Google, please let me know). Does...
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
3
by: | last post by:
I am working on a web/webservice application that has a service layer. Most service methods will perform an access-check before executing. This check uses the IPrincipal credentials available in...
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: ...
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...
1
by: rich_sposato | last post by:
I released version 2.0 of C++ Unit Test Library. You can download it from SourceForget.Net at http://sourceforge.net/projects/cppunittest/ .. I wrote this unit test library because other unit...
27
by: brad | last post by:
Does anyone else feel that unittesting is too much work? Not in general, just the official unittest module for small to medium sized projects? It seems easier to write some quick methods that are...
5
by: Ben Finney | last post by:
Howdy all, PEP 299 <URL:http://www.python.org/dev/peps/pep-0299details an enhancement for entry points to Python programs: a module attribute (named '__main__') that will be automatically called...
2
by: Steve | last post by:
Hi guys, I have a test solution (called TP2) which is checked in to a Team Project (also called TP2). The solution contains: * DLL (containing a single test class) * Unit Test project (which...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.