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):
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:
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
Are you looking for a "Coverage" tool, such as Emma or Cobertura?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With