문제

Occasionally I am looking at some code, I search for usages of a method (using resharper) and find that it is only called by tests. So it's effectively redundant and I can delete it and the methods that call it.

Obviously there's no point in having unused code lying around the place, slowing down the build and the test run. What I'd like is a tool that can tell me where all the bits of production code are that are only accessed by tests.

I have a full version of resharper, and also a trial version of NDepend, but haven't found out how to use either of these to get the result I want (without paying for it). I suspect It may be possible with the full version of NDepend but are there any other tools that people know about?

If the context helps, the solution is and ASP.net website, much of whose functionality is handled by a WCF service. So the only valid entry points to the bulk of the code are the service methods. The tests are in their own seperate projects.

I've started a bounty because I'm sure someone else must have had and solved this problem before!

도움이 되었습니까?

해결책

Manually looking with NDepend should work with the Dependency Matrix. There you can see which methods are used only by the Unit Test Assemblies.

I'm not sure if you can write own CQL Queries with the Trial Version. But with the Pro Version you could use a Query like this:

SELECT METHODS WHERE IsUsedBy "ASSEMBLY:NAME_OF_THE_UNIT_TEST_ASSEMBLY" 
AND !(IsUsedBy "ASSEMBLY:NAME_OF_ANOTHER_ASSEMBLY" OR IsUsedBy "ASSEMBLY:ANOTHER_NAME")

For this to work you have to create a NDepend Project that knows all your Assemblies.

For NAME_OF_THE_UNIT_TEST_ASSEMBLY you have to insert your Unit Test Assembly and in the second part you have to specify you Production Code Assemblies with IsUsedBy and seperated with OR.

다른 팁

A non-technical approach would be to temporarily remove you test project from your solution, then use Visual Studio's code analysis (or FxCop) to locate any methods that are not being called by anything else.

You could use NDepend with some custom queries... That's just off the top of my head, never used it for exactly that, but it should work.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top