Domanda

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:

public class UnitTest {    
  public main() {
    Circle c = new Circle()
    c.getArea()
  }
} 

public class Circle {
  public Circle() {
    ...
  }    
  public getArea() {
    ...
    getRadius()
  }
  private getRadius() {
    ...
  }
}

The method calls of the UnitTest class follow this order (though for my purposes I don't need to preserve order, or to know of the caller's method):

  1. UnitTest.main
  2. Circle.Circle
  3. Circle.getArea
  4. Circle.getRadius

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.

The approaches I am thinking of using would be either:

  • Using a Java Agent to print out the class.method at every method call.
  • Tracing using Aspects like this

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.

Any help/suggestions would be appreciated.

UPDATE-SOLVED 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):

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
È stato utile?

Soluzione

Are you looking for a "Coverage" tool, such as Emma or Cobertura?

Altri suggerimenti

If you want to know which methods are called by your test you can use a code coverage tools like cobertura or emma.

Both of them provide a great integration with maven ,ant and eclipse and can produce a xml or html report.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top