Re: Am I Running Under NUnit?

"Charlie Poole" <[email protected]>
Newsgroups gmane.comp.windows.dotnet.nunit.user
Message-ID <016601c89f21$0786a1a0$6401a8c0@ferrari>
Hi Ron,
 
Our conversation appears to have fallen off the list - I put us back on it.
 
I'm confused... You already reference NUnit from your production code?
I'm assuming that's what we are talking about - if you want to figure out
whether your tests are running under NUnit or some other runner, that's
a different - perhaps a simpler - matter.
 
As far as being forced to use a hack: the entire notion seems like a
hack to me, and NUnit can't do anything to improve it. We can't even
hide the hack for you, since we have no general way to determine if
some arbitrary code is running under NUnit - and it would have to be
a general solution if NUnit implemented it, while you can simply do
something that works for your own particular case.
 
In fact, NUnit's lack of knowledge of where threads originate is already
a source of difficulty for us - one I hope to solve as part of the 3.0
rewrite.
 
If I'm misunderstanding something here, please let me know, but this
does not sound like a service NUnit can readily provide.
 
Charlie
 
I


  _____  

From: Ron Gross [mailto:[email protected]] 
Sent: Monday, April 14, 2008 11:13 PM
To: Charlie Poole
Subject: Re: [Nunit-users] Am I Running Under NUnit?


So you think it's better for me to do this hacks than for you to expose a
method?
After all, I am dependant on NUnit and reference it anyway.

Only this way, I'm forced to these ugly hacks.


On Tue, Apr 15, 2008 at 12:52 AM, Charlie Poole
<[email protected]> wrote:


Yes, your original method suffers from the same problem if threads are
involved.
 
If we exported such a function, then people would have to reference it,
making their apps 
dependent on NUnit - so no. :-)
 
Another possibility is to look at the entry assembly and see if it's
nunit.exe or nunit.console.
However, that may not work in a secondary AppDomain - I'm not sure.
 
Charlie
 


  _____  

From: Ron Gross [mailto:[email protected]] 
Sent: Monday, April 14, 2008 1:13 PM
To: Charlie Poole
Subject: Re: [Nunit-users] Am I Running Under NUnit?


The 2nd way is not perfect, because if the call is made from another thread
then its stack will not have any NUnit frames.
Is there a chance such a function can be exported from NUnit itself in some
future release?


On Mon, Apr 14, 2008 at 10:15 PM, Charlie Poole
<[email protected]> wrote:


Hi Ron,
 
The code is wrong on several levels:
 
1) Tactically, because it will fail if your test references a different
version of the framework than the one it
was built against.
 
2) Strategically, because the presense of a Test attribute doesn't have to
mean your test is running under
NUnit. However, it may be so for a particular user who never calls the tests
any other way.
 
There are two simple ways to test whether you are running under NUnit... 
 
One is to look at the friendly name of the current appdomain, which is
"domain-<project>" where <project> 
is the name of the assembly or project being executed. Obviously, this is
subject to name clashes.
 
The other - and more accurate - is to search the stack for the name of the
nunit.core assembly.
 
Charlie


  _____  

From: [email protected]
[mailto:[email protected]] On Behalf Of Ron Gross
Sent: Monday, April 14, 2008 7:50 AM
To: [email protected]
Subject: [Nunit-users] Am I Running Under NUnit?


How can I implement a function AmIRunningUnderNUnit() ?
I have a logger, and I want to Log only if I'm running under NUnit.

This is a suggested solution:
http://geekswithblogs.net/ajohns/archive/2004/08/05/9389.aspx

But it doesn't work if the test spawns different threads and the function is
called from there.

Thanks,
Ron



-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javao
ne
_______________________________________________
Nunit-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nunit-users

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

_______________________________________________
Nunit-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nunit-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.