Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if the running code is unit test case or not

I want to check if the running code is unit tese case or not execute different code for the result such as:

    if ( unit test case is running )
{
do something
}
else
{
do other thing
}

any idea on this?

like image 226
Prajwal Udupa Avatar asked Jan 15 '13 07:01

Prajwal Udupa


People also ask

Is it a unit test or an unit test?

A unit test is a way of testing a unit - the smallest piece of code that can be logically isolated in a system. In most programming languages, that is a function, a subroutine, a method or property. The isolated part of the definition is important.

Is unit testing done after code check in?

Unit Testing is done during the development (coding phase) of an application by the developers. Unit Tests isolate a section of code and verify its correctness.


1 Answers

This is a bad approach you should try to simulate logic parts which you are trying to avoid by this statemetn through Mock ojects or other mechanism.

Now to your question you can use a oolean variable like isUnittest which you set on test setup and Teardown, ut as saied i dont recommend you doing this.

like image 134
CloudyMarble Avatar answered Sep 30 '22 07:09

CloudyMarble