title: List of Method Calls During Execution of Java Unit Test
body: <p>I have a situation where I need to know what methods are being called from a single JUnit test. For example, if I have the following pseudo-code:</p>
  
  <pre><code>public class UnitTest {    
    public main() {
      Circle c = new Circle()
      c.getArea()
    }
  } 
  
  public class Circle {
    public Circle() {
      ...
    }    
    public getArea() {
      ...
      getRadius()
    }
    private getRadius() {
      ...
    }
  }
  </code></pre>
  
  <p>The method calls of the <em>UnitTest</em> class follow this order (though for my purposes I don't need to preserve order, or to know of the caller's method):</p>
  
  <ol>
  <li>UnitTest.main</li>
  <li>Circle.Circle</li>
  <li>Circle.getArea</li>
  <li>Circle.getRadius</li>
  </ol>
  
  <p>Essentially, I want to know what part of the program is actually being exercised in the JUnit tests. I figure I can dynamically figure this out, but I am having trouble finding a tool or approach. The main problem with some of the tools I have found is that they are often very visual (require user interaction to extract the required data). I am looking for something that gives me just a list of the methods (xml, text, etc...) without the GUI aspect. In the end I am trying to automate this for test suites via a scripting approach.</p>
  
  <p>The approaches I am thinking of using would be either:</p>
  
  <ul>
  <li>Using a Java Agent to print out the <em>class.method</em> at every method call.</li>
  <li>Tracing using Aspects <a href="http://www.eclipse.org/aspectj/doc/released/progguide/examples-development.html#tracing-using-aspects" rel="nofollow">like this</a></li>
  </ul>
  
  <p>If there is a tool which already does this that would be great. If not, does it seem like I am on track to solve my problem using one of the approaches I've specified. </p>
  
  <p>Any help/suggestions would be appreciated.</p>
  
  <p><strong>UPDATE-SOLVED</strong>
  I decided to use Emma with the following commands to extract the information of method calls (just need to parse report for any method over a 0% coverage):</p>
  
  <pre><code>emmarun -r xml                 // To output to XML
    -Dreport.sort=-method        // Sort method coverage in descending order
    -Dverbosity.level=silent     // Minimize script output
    -Dreport.metrics=method:1    // Flag any method with a 0% coverage
    -Dreport.columns=method,name // Only show the method and name columns
    -Dreport.depth=method        // Consider the data of method coverage
  </code></pre>