Organize using directives, rerun tests?

Before committing, I prefer to run all the hundred-unit tests in my C # solution, since they only take a couple of minutes. However, if I already ran them, everything is fine, and then I decided to organize using directives in my decision, do I really need to restart unit tests? I have a macro that goes through all the files in the solution and runs the "Delete and Sort" Visual Studio command on each of them. In my understanding, if all projects are still built after using directives are changed, everything should be fine at runtime. Is that the right way of thinking?

+4
source share
3 answers

Well, that partly depends on how much you trust the delete and sort feature. As far as I know, the order does not matter, but which directives are present may matter.

For example, suppose you have this extension method:

 public static int Count<T>(this List<T> source) { return 0; } 

If it was in a type in the MyExtensions namespace, and the source code was as follows:

 using MyExtensions; using System.Linq; ... List<string> list = new List<string>(); int x = list.Count(); 

then removing the first using directive will not make any difference to the output of the visible compiler (i.e. no errors, no warnings), but it will change which extension method was called.

Now I personally think that โ€œdelete and sortโ€ will not really make such a change that changes behavior, and you will need to have pretty fragile code to start with ... but I just thought I would mention that โ€œhe still building afterwards "is actually not enough to guarantee that your tests will work anyway.

Personally, I would probably run the tests again, but equally I would not be happy if necessary. As Finglas mentions, if you have a continuous build system that in any case warns you that you are breaking changes, the consequences are often erroneous, probably not too catastrophic. Of course, if you have thousands of developers who are unsatisfied with the broken code that will be tested, this is another matter.

+2
source

It does not matter.

Personally, however, I still ran tests before executing any code.

+1
source

Yes. Restarting unit tests is not required. The order of using directives does not matter to the compiler.

0
source

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


All Articles