PC Review


Reply
Thread Tools Rate Thread

detecting running under UNIT TEST

 
 
Ing. Davide Piras
Guest
Posts: n/a
 
      13th Feb 2007
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.


 
Reply With Quote
 
 
 
 
Markus Becker
Guest
Posts: n/a
 
      13th Feb 2007
Ing. Davide Piras <(E-Mail Removed)> schrieb:

> 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
 
Reply With Quote
 
Ing. Davide Piras
Guest
Posts: n/a
 
      13th Feb 2007
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.


 
Reply With Quote
 
PS
Guest
Posts: n/a
 
      14th Feb 2007

"Ing. Davide Piras" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Restoring state of database after running a Unit test sprash Microsoft C# .NET 1 16th Feb 2008 09:24 AM
Unit Test returns dataprovider while running the app itself is not able to find the dataprovider vsv Microsoft ADO .NET 0 9th Aug 2007 05:53 PM
VSTS Unit Testing test list and test manager missing Brett Microsoft Dot NET 0 8th Jun 2006 01:36 AM
separating test data from test code + creating skeleton unit test classes QA Guy Microsoft C# .NET 0 6th Apr 2005 10:00 AM
separating test data from test code + creating skeleton unit test classes qualityassurance@gmail.com Microsoft C# .NET 0 6th Apr 2005 09:38 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:47 AM.