单元测试的接口问题

现实中经常会在类中拆分为一些小方法为private,这些方法是不在interface上暴露给外部的

现在想在细粒度上对这些private方法做单元测试,可是继承TestCase的类无法找到这些方法,除非把这些方法标记为public
[code="java"]
public class AlarmQueryDAOTest extends TestCase
{

private IAlarmQueryDAO dao;

protected void setUp() throws Exception
{
    ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
    dao = (IAlarmQueryDAO)context.getBean("alarmQueryDao");
}

public void testGet()
{
    ReporterStatus rs = dao.get(123L);
}

}
[/code]

请问有什么办法,既可以保持这些方法为private,又能在单元测试类中调用呢?

1,不对private方法进行测试,因为他们不会被外界所调用,只要确保所有的public和protected方法是正常运行的就达到目的了。
2,如果private中含有必须要测试的东西,那么就应该独立为一个Class,再对Class进行单元测试。
3,如果一定要在本类中进行测试private方法,那就把private改成protected,然后再不同的源文件夹中组织相同的包结构,用其中的UnitTest对这个protected方法进行测试。
如:被测程序src-->com.moyan.MyClass 测试程序test-->com.moyan.TestMyClass

希望对你有帮助.