4

コネクタが NioSocketConnector である mina クライアントがあります。このクライアントと実サーバーの統合テストを作成しました。しかし、単体テストを行う方法が見つかりませんでした。たとえば、実際のソケットを開かずに、カスタム デコーダーとエンコーダーが正しく動作することをテストしたいと考えています。そして、メッセージがバッファなどに正しくキューに入れられていることをテストしたい.

テスト用の DummySession クラスを見つけましたが、このクラスがクライアントの完全な単体テストに十分かどうかはわかりません。

Mina は単体テストが簡単だと言っています。あなたのアイデアやサンプルコードへのリンクを手伝ってください。

前もって感謝します。

4

1 に答える 1

8

エンコーダの単体テスト:

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()
于 2012-10-14T14:37:51.697 に答える