jeudi 16 avril 2020

Testing a Component with a TcpStream

I have created a component that creates a std::net::TcpStream and over its lifetime of course reads from it and writes to it. Now I would like to write tests for it; does it connect to the right address? Does it send the correct data? Can it handle receiving invalid data? However, as I have only started using Rust, like, three days ago, I am unsure as to how to proceed. In Java (which I have been doing substantially longer than Rust) I would have at least the following possibilities:

  1. Create a test TCP server to collect data sent to it and to control what is being sent back.
  2. Extract the I/O operations into a trait, implement that trait for TcpStream and a TestTcpStream, and use the TestTcpStream during tests.

Does Rust offer something else that I don’t yet know about?

Aucun commentaire:

Enregistrer un commentaire