【问题标题】:Unit testing of an apache mina clientapache mina 客户端的单元测试
【发布时间】:2012-08-23 18:08:35
【问题描述】:

我有一个连接器是 NioSocketConnector 的 mina 客户端。我已经编写了这个客户端与真实服务器的集成测试。但是,我找不到进行单元测试的方法。例如,我想在不打开真实套接字的情况下测试我的自定义解码器和编码器是否正常工作。而且,我想测试我的消息在缓冲区等中是否正确排队。

我找到了一个用于测试的 DummySession 类,但我不确定这个类是否足以对客户端进行完整的单元测试。

Mina 建议使用它进行单元测试很容易,所以我真的想知道我该怎么做。请提供您的想法或示例代码链接。

提前致谢。

【问题讨论】:

    标签: unit-testing apache-mina


    【解决方案1】:

    编码器的单元测试:

    YourEncoder encoder = new YourEncoder();
    ProtocolCodecSession session = new ProtocolCodecSession();
    encoder.encode(session, message, session.getEncoderOutput());
    // encoded message will be in session.getEncoderOutputQueue()
    

    解码器的单元测试:

    //Prepare an IoBuffer which will be decoded, say buf
    YourDecoder decoder = new YourDecoder();
    ProtocolCodecSession session = new ProtocolCodecSession();
    decoder.decode(session, buf, session.getDecoderOutput());
    //decoded message will be in session.getDecoderOutputQueue()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-03
      • 1970-01-01
      相关资源
      最近更新 更多