keyongtech


  keyongtech > dotnet.languages.* > dotnet.languages.csharp > 02/2007

 #1  
02-13-07, 11:03 PM
Ing. Davide Piras
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.
 #2  
02-13-07, 11:17 PM
Markus Becker
Ing. Davide Piras <davide> 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
 #3  
02-13-07, 11:39 PM
Ing. Davide Piras
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.
 #4  
02-14-07, 12:19 AM
PS
"Ing. Davide Piras" <davide> wrote in message
news:1364
> 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
Similar Threads
Running Unit Test Remotely

Hi, Some of my future unit / component test may run op to several hours. I would like to run them simultaneously and on a different machine. Arguably, I misuse the unit...

Why does running a Test::unit test in irb work so weirdly?

Why can't I run a Test::Unit::TestCase from IRB and have it run before I quit? I have found this problem mentioned by others. For an example, see this tutorial about...

Restoring state of database after running a Unit test

Sorry if this is a newbie question. My application sends data (via TCP/IP sockets) to a 3rd party application which dispenses the data to various tables in a SQL Server 2005...

Test::Unit running all tests with automated suite

Am I missing something when using Test::Unit in Eclipse? I am used to using JUnit and/or NUnit and being able to select a project and run all of the tests. I don't see this...

Running one test with test/unit

Hi, As per this page[1], it is possible to run one test from a testcase by using.. # ruby [programfile] -n [testmethod] I'm probably missing something obvious but I really...


All times are GMT. The time now is 05:59 PM. | Privacy Policy