best practice to unit test a class that relies on threads
hi,
i'm trying to to test some hardware device connected through COM port.
it seems the best way to communicate with such a device using C# is through the SerialPort class discussed on MSDN there http://
the provided sample code works and is pretty much self explanatory
it pretty much looks like the following
1. in the main thread, instantiate the static SerialPort objet, stuff it with paramaters (baudRate, parity, etc), open the port, then create a new thread to start listening
2. the other thread simply loops on some serialPort.read() and display response on Console as long as a common flag remains true
3. still in the main thread user is prompted for some commands to the sent to the port.
4. if user types in "exit" then the common flag is set to false, second thread .Join() method is called so that it closes gracefully, COM port is closed and then program exits
it's been working more or less. but before going any further, i want to replay such actions with Nunit.
i have read http://
it seems the most appropriate way to do this is by using some sort of trick like this one here :http://
i have the feeling i have simply to (re)design my custum class handling the multithread operations but i am confused as what is the best approach ? i want some strong and testable code
anyone has any thought share about multi threading tests using Nunit ?
Question information
- Language:
- English Edit question
- Status:
- Answered
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask fourchette for more information if necessary.