Eclipseプラグインのクラスローダーは、異なるプラグインからprotectedメンバへのアクセスを許さないようです。
したがって、プラグインプロジェクトとテストプロジェクトを別にしていると、protectedメソッドテストができません。
someplugin
└foo.bar.SomeThing.java
someplugin-test
└foo.bar.SomeThingTest.java
SomeThing に
protected void protectedMethod() みたいなメソッドがあるとき、
SomeThingTest で
public void testProtectedMethod(){
SomeThing st = new SomeThing();
st.protectedMethod(); // ここでIllegalAccessError が発生します。
}
PDE JUnit ではなく単体のJUnitを使う場合は、パッケージが同じなのでprotectedでもアクセスできるんですが、プラグインとしてEclipseランタイム上で動作する場合は、アクセスできません。
リフレクションを使ったらアクセスできました。
public void testProtectedMethod(){
Method method =
SomeThing.class.getDeclaredMethod("protectedMethod", null);
SomeThing st = new SomeThing();
method.invoke(st, null);
}