C #: using conditional attribute for tests

Is there a good way to use a conditional attribute in a testing context?

My thoughts were that if you can do this:

[Conditional("Debug")]
public void DebugMethod()
{
    //...
}

Perhaps you could use for: (?)

[Conditional("Test")]
public void TestableMethod()
{
    //...
}
+3
source share
4 answers

I do not see the point when there is a better alternative: test projects.

Use NUnit or MSTest to achieve this feature in a more elegant way.

+4
source

I would accept Mehrdad's answer - I just wanted to give more context when you can use these attributes:

, [Conditional], , / ; , , , , ( #if... .. ).

+1

, . , , , #if, , .

, . , ( , ), .

Let the test code be the test code, and the production code the production code, and let the production code have no idea about it.

+1
source

Another problem is that you might want to run your unit tests in your release builds. (We certainly do).

+1
source

Source: https://habr.com/ru/post/1710234/


All Articles