5
使用JMockit 0.999.4和JDK6,是否可以調試到部分模擬類中?在JMockit中調試部分模擬
考慮以下測試:
@Test
public void testClass() {
SampleClass cls = new SampleClass();
System.out.println(cls.getStaticInt());
cls.setVal(25);
System.out.println(cls.getVal());
}
static class SampleClass {
static int staticInt = 5;
private int val;
{
staticInt = 10;
}
public int getStaticInt() {
System.out.println("Returning static int and adding a line for debugging");
return staticInt;
}
public void setVal(int num) {
System.out.println("Setting val and adding a line for debugging");
this.val = num;
}
public int getVal() {
System.out.println("Returning val and adding a line for debugging");
return this.val;
}
}
每個在SampleClass和調試系統輸出線的放置斷點「步過」在Eclipse將進入SampleClass方法。
考慮,這將防止靜態初始化從設置staticInt至10
@Test
public void testClass(@Mocked(methods = "$clinit") SampleClass cls) {
System.out.println(cls.getStaticInt());
cls.setVal(25);
System.out.println(cls.getVal());
}
static class SampleClass {
static int staticInt = 5;
private int val;
{
staticInt = 10;
}
public int getStaticInt() {
System.out.println("Returning static int and adding a line for debugging");
return staticInt;
}
public void setVal(int num) {
System.out.println("Setting val and adding a line for debugging");
this.val = num;
}
public int getVal() {
System.out.println("Returning val and adding a line for debugging");
return this.val;
}
}
一個值。然而,這個代碼將不會調試到在SampleClass方法如下。
是的,我試過了-javaagent屬性。
對於好奇,這是JVM錯誤鏈接:https://bugs.openjdk.java.net/browse/JDK-7036136 – 2014-06-26 21:15:30