Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect if an NUnit test is running from within TeamCity?

I need to run some code only if I'm running from within the TeamCity test launcher. What's the easiest way to detect this?

like image 748
ripper234 Avatar asked Dec 15 '09 13:12

ripper234


1 Answers

Check if TEAMCITY_VERSION environment variable is defined.

Another approach is to use NUnit categories.

Based on the comment below this code should be able to check if the test is being run by teamcity:

private static bool IsOnTeamCity() 
{ 
    string environmentVariableValue = Environment.GetEnvironmentVariable("TEAMCITY_VERSION"); 
    if (!string.IsNullOrEmpty(environmentVariableValue)) 
    { 
         return true; 
    } 
    return false; 
} 
like image 71
Eugene Petrenko Avatar answered Oct 16 '22 17:10

Eugene Petrenko