简体   繁体   中英

Unit testing runtime objects

I'm following the Tweet ingestion tutorial from Cloudera here and here . The libraries involved here are Twitter4J and Flume.

However, my question here is related to unit testing, so even those who are knowledgeable about unit testing (JUnit, Mockito, PowerMock, etc.) may answer, even if not knowledgeable about Twitter4J or Big Data component like Flume.

I have a class that I wish to test:

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 is a runtime object, existing only when I run the entire application (Flume agent to be exact), which I don't know how to mock and test. Can anyone give an idea how to do this?

The easiest way to do this is to create a thin wrapper object for it, and mock it. You can look at a similar response here: How do you test code written against AWS API

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM