测试无法访问变量

时间:2016-03-03 00:06:49

标签: java eclipse evaluator

public class Saiyan extends PlayableFighter {
private boolean transformed;
public Saiyan(....)
{
    :
    :
}

public void isTransformed(boolean x){
transformed=x;

}
public boolean isTransformed(){
    return transformed;
}

}

我认为我的转换属性应该是读写的,但是当我运行我的测试时,我得到了这个错误

M1PrivateTest.testSaiyanClassWRITEVariables 0/1  
   junit.framework.AssertionFailedError
   junit.framework.AssertionFailedError:
   The "transformed" instance variable in
    class Saiyan is a WRITE variable. 
    at M1PrivateTest.testSaiyanClassWRITEVariables(Unknown Source) at  
      java.util.concurrent.FutureTask.run(FutureTask.java:266) at
       java.lang.Thread.run(Thread.java:745)

1 个答案:

答案 0 :(得分:1)

更改为

public void setTransformed(boolean transformed){
    this.transformed=transformed;
}

按照普通的setter / getters模式