单元测试运行时对象

Unit testing runtime objects

我正在学习 Cloudera here and here 的推文提取教程。这里涉及到的库有Twitter4J和Flume.

然而,我这里的问题与单元测试有关,所以即使那些了解单元测试(JUnit、Mockito、PowerMock 等)的人也可以回答,即使不了解 Twitter4J 或大数据组件,如 Flume.

我有一个 class 想要测试:

class TwitterConnection {

    public TwitterConnection setCredentialsFromFlumeConfig(Context context) {

        // get variables from Flume agent config file using org.apache.flume.Context

        return this;
    }

}

org.apache.flume.Context 是一个 运行time 对象,仅当我 运行 整个应用程序(确切地说是 Flume 代理)时才存在,我不知道如何模拟和测试。谁能告诉我怎么做?

最简单的方法是为它创建一个薄包装对象,然后模拟它。 您可以在此处查看类似的回复:How do you test code written against AWS API