假设我有一个类,就像这样:
public class ClassA
{
[...]
protected void methodIWantToTest()
{
[...]
}
[...]
}
当我在IntelliJ Idea 13中编写单元测试时,如果我写下类似如下的代码,编译器不会报错:
public class ClassATest
{
@Test
public void test()
{
final ClassA objectUnderTest = new ClassA();
objectUnderTest.methodIWantToTest(); // Why can I access a protected method here?
}
}
methodIWantToTest
是受保护的方法。为什么我可以在测试中访问它?