需要使用Mockito进行B类的Junit测试用例,任何人都可以帮助我

时间:2019-05-26 15:42:12

标签: java junit mockito powermockito

我正在努力编写junit测试用例,任何人都可以解释如何使用Mockito。 A is接口我必须模拟b并需要为b编写测试用例。在b类中,在方法内部为c创建对象。

Interface A
{
public void dial();
}

public class B implments A
{
public void dial()
C c = new C(username,password);
c.regularcommand();
}

//how to mock for this classs
public class c()
{
private string username;
private String password;
public c(username,password)
{
this.username=username;
this.password=password;
try {
            boolean sessionCreated = setup(username, password);
            if (sessionCreated) {
                sessionMap.put(ip, new DeviceSession(sess, conn));
            }
        } catch (IOException e) {
            close();
            e.printStackTrace(System.err);
        }
}
//innerclass
private class endpointSession {
        private final Session sess;
        private final Connection conn;
        public DeviceSession(Session sess, Connection conn) {
            super();
            this.sess = sess;
            this.conn = conn;
            }
}
}

0 个答案:

没有答案