How to find all unit tests that can directly or indirectly call this method? (.net)

How to find all unit tests that can directly or indirectly call this method? When I change a method, I want to know the best tests to run; there must be a tool for this!

Since we have many interfaces, I'm interested in all the unit tests that call a method on an interface when there is at least one way var implant method for a class that implements the interface.

In other words, I want the list of all unit tests, when the tool could not prove that the result is not changing, to change the method.

(We use nUnit for .net and have many slow unit tests, it will be many years until we have reorganized all our unit tests quickly)

see also:

  • How to find Junit tests that use this Java method directly or indirectly
+3
unit-testing code-analysis static-code-analysis
source share
4 answers

Visual Studio 2010 has this exact function: http://blogs.msdn.com/b/phuene/archive/2009/12/07/test-impact-analysis-in-visual-studio-2010.aspx

Since you are using nunit, you can try this technique to run MSTest: http://msdn.microsoft.com/en-gb/magazine/cc163643.aspx#S4

+3
source share

In the most general case, when you use delegates, lambda expressions, etc., I have an intuition that this problem is equivalent to checking for the completion of a given program ( "Problem with stopping"), so I do not hope to find a reasonable answer.

If your real goal is to quickly check if your change has changed, I would recommend:

  • refactoring your tests
  • Configuring the parallel build infrastructure using a cluster of build machines (easier than you might think with modern tools like TeamCity).
+1
source share

You need a connection between each test and the code that it runs.

It can be calculated statically, but it is complicated, and I do not know any tools that do this. Even worse, if you had such a tool, a static analysis, to decide what the test influenced, it may take more time than just running the test itself, so this does not look like an attractive direction.

However, this can be calculated using a testing tool. For each individual test, run this test (we assume that it passes) and collect test coverage data. Now we have many pairs (t_i, c_i) for "test I have cover c".

When the code base changes, you can familiarize yourself with test data coverage sets. A simple check: if for any (t_i, c_i), if c_i mentions the file F and F has changed, you need to run t_i again. Test coverage data in almost any representation is easy to find in an abstract form. Given that most testing tools do not specify how they store test coverage data, this is more complicated than it seems in practice.

Actually, you go perfectly, if c_i mentions any program element F and that program element has changed, you need to run t_i again.

Our SD test testing tools provide this feature for Java and C # at the method level. You need to configure some scenarios to link the actual test, however you packaged it with the collected test coverage vectors. In practice, this tends to be fairly easy.

+1
source share

You can use VS2010 View Hierarchy of Calls or ReSharpers ReSharper β†’ Inspect β†’ Incoming calls. You can even export the result from ReSharper.
If you want to use automation to achieve your goal, i.e. Because this is not a one-time thing, but what you want to integrate into your build process, I suggest you build your own solution. You can use Reflection or Mono.Cecil on assemblies and go through the call hierarchy yourself. However, this can be time consuming because you will need to create a complete call hierarchy tree over all your assemblies. Another option is to create a Visual Studio or ReSharper plugin so that you can access the object model they created from the source code.
Basically, I say: I don’t know about the currently existing method of achieving your goal using automation, and writing my own solution will be fun, but difficult and possibly a lot of time, either during development or at startup.

0
source share

All Articles