1

I am wondering what to do to take a deeper insight into the execution flow when running a test unit.

For example, below should be a body of a test unit.

A.methodA(1,2,false);
B b = new B("foo");
boolean c = b.testFoo("abc",true);

Below bodies are found by JVM on classpath.

What I want to ask is, the bytecode of test unit is the only bytecode passed to ASM transformer, in this scenario, can I modify the bytecode of class A and class B?

below should be the body of A

Class A{
public static methodA(int a,int b, boolean c){
    if(c) System.out.println(a+b);
    else System.out.println(a-b);
}
}

below should be the body of B

Class B
{
  String n;
  public B(String c) {this.n = c;}
  public boolean testFoo(String temp,boolean b)
  {
    boolean tested = temp.equals(this.n);
    return tested.equals(b);
  }
}

When I pass the bytecode of test unit to the ASM transformer, can it be able to modify the bytecode of Class A and Class B?

6
  • Yes, it can modify the bytecode. Commented Apr 6, 2023 at 7:51
  • 4
    There’s a contradiction between your question’s title (“How to check the whole execution flow”) and the question eventually asked (“is it able to modify the bytecode”). Further, there’s a lot of context missing. To analyze the bytecode, you need access to it, which depends on the environment your analyzer is running in. You can always modify it, producing new modified bytecode, but how you can pass it to an execution environment to use it, depends on the environment supposed to use it (and again, on the environment your analyzer is running in). Commented Apr 6, 2023 at 8:41
  • @Holger I am sorry for I didn't clearify my question. Thanks for your reply. and what I want to ask is, the bytecode of test unit is the only bytecode passed to ASM transformer, in this scenario, can I modify the bytecode of class A and class B? If I did not misunderstand what you mean, do you mean that the answer to my question is based on the environment that my analyzer in running in? Commented Apr 6, 2023 at 11:17
  • @JohannesKuhn thanks to your reply. I am sorry I didn't clearify my question. What I want to ask is, the bytecode of test unit is the only bytecode passed to ASM transformer, in this scenario, can I modify the bytecode of class A and class B? Commented Apr 6, 2023 at 11:18
  • 1
    A transformer only modifies one class per call. You can of course record information that is used by other transformations later on. I don't know how you execute the transformer (static tool, java agent...). Commented Apr 6, 2023 at 13:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.