Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Conditional Compilation
Message
De
12/01/2009 15:50:46
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
12/01/2009 12:35:17
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01372770
Message ID:
01372945
Vues:
24
>>Hi.
>>I would like to use conditional compilation to have difference method access modifier for unit testing.
>>
>>
>>#if TEST
>>    public virtual void MyMethod()
>>#else
>>    public void MyMethod()
>>#endif
>>    {
>>        // Do Something;
>>    }
>>
>>
>>I have code as above, I added new constant TEST at solution configuration manager. I changed "constant" among debug, release and TEST. VS 2008 IDE works fine for TEST and debug. However, whenever I change it to release, the method under TEST constant will be used.
>>
>>Anyway to make DEBUG/RELEASE to use public void MyMethod() and onyl TEST will use public virtual void MyMethod() ?
>
>If I understand correctly what you are trying to do:
>
>There is a pre-defined DEBUG constant which should be adequate - just make sure the checkbox in the project 'Build' page is checked for the relevant configurations. You should be able to check whether conditional code will be compiled - if it is not being compiled it will be greyed-out in the IDE. If you really want to use 'TEST' then add it to the 'Conditional Compilation symbols in the 'Debug' configuration of the project properties 'Build' page


You can also test for debug mode
if (System.Diagnostics.Debugger.IsAttached)
{
     DoSomething()
}
else
{
     DoSomethingElse()
}
Timothy Bryan
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform