开发者

organize using directives, re-run tests?

Before making a commit, I prefer to开发者_JS百科 run all hundred-something unit tests in my C# Solution, since they only take a couple minutes to run. However, if I've already run them all, all is well, and then I decide to organize the using directives in my Solution, is it really necessary to re-run the unit tests? I have a macro that goes through all files in the Solution and runs Visual Studio's 'Remove and Sort' command on each. In my understanding, so long as all projects still build after using directives are changed around, things should be fine at runtime, too. Is this correct thinking?


Well, it partly depends on how much you trust the "remove and sort" feature. As far as I'm aware, the ordering doesn't matter - but which directives are present can matter.

For example, suppose you had this extension method:

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

If this were in a type in a namespace MyExtensions, and the original code was this:

using MyExtensions;
using System.Linq;

...
List<string> list = new List<string>();
int x = list.Count();

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

Now I personally trust that "remove and sort" won't actually make such a behaviour-changing alteration, and you'd have to have some pretty brittle code to start with... but I just thought I'd mention that "it still builds afterwards" isn't actually enough to guarantee that your tests will still work.

Personally I'd probably run the tests again anyway, but equally I'd be reasonably happy not to if necessary. As Finglas mentions, if you've got a continuous build system alerting you to breaking changes anyway, the consequences of very occasionally getting it wrong probably aren't too disastrous. Of course, if you've got thousands of developers who will be inconvenienced by broken code getting checked in, that's a different matter.


It will not matter.

Personally though, I'd still run tests prior to committing any code.


Yes. Re-running the unit tests is not necessary. The order of using directives does not matter to the compiler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜