Search code examples
javacode-coverageline-numbers

Control the execution of a java program from my java program


public class LineNum1 extends Thread{

    public synchronized void run()
         {
          try {
                Hello.main(null);
                System.out.println("Stack Trace of thread"+ this.currentThread().getName());
                System.out.println(this.currentThread().getStackTrace()[1].getLineNumber());
                System.out.println("End of Stack Trace");
               } catch (Exception e1) {
                    e1.printStackTrace();
               }
            }

     public static void main(String[] args) {

                LineNum1 t = new LineNum1();
                t.start();
            }
   }

I'm developing a code coverage tool.

Using the above program I'm executing Hello.java from here. Is there any method where I can get the control over Hello.java?

Or to make my life simpler can i get the line numbers of the executed lines(Execution path) of Hello.java?


Solution

  • I have not completed the code coverage completely yet. But I have used bytecode instrumentation to instrument the methods, hence i get the log of all the methods I've visited. This Javassist Turtorial might help you.