2012-08-23 95 views
3

我有一個mina客戶端,其連接器是NioSocketConnector。我已經編寫了這個客戶端與真實服務器的集成測試。但是,我找不到一種方法來做單元測試。例如,我想測試我的自定義解碼器和編碼器是否正常工作,無需打開真實的套接字。而且,我想測試我的消息在緩衝區等中是否正確排隊。apache mina客戶端的單元測試

我發現DummySession類用於測試,但我不確定此類是否足以完成客戶端的單元測試。

Mina建議單元測試很容易,所以我真的想知道我該怎麼做。請幫助你的想法或示例代碼的鏈接。

在此先感謝。編碼器的

回答

6

單元測試:解碼器的

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() 
相關問題