C Serial Port Unit Test
Please note: assume this serial port is on remote, non attached computer. Scenario: I'm writing a c#,.NET 4 program to read and parse data from a computer that is attached to a non computer device that does have a specialized 'computer' for capturing data. This data can be downloaded through a serial cable with a program like Windows HyperTerminal. A 'capture' text file is created for later processing. I've a separate program that parses the downloaded data from the specialized 'computer'.
Is there any way to make unit testing plain C code as. From the ANSI / ISO C libraries. It also has a Windows port. Addresses unit testing C code.
I want to replace the manual downloading with a c#.NET 4 program that automates the downloading of the serial port data. Since my development environment is not even connected to the target computer, I need to simulate the transfer of serial data in order to use TDD and xUnit.net to ensure as best as possible that my program is robust and as correct as possible before I actually test it in the 'real world' environment. I'm wondering how I might use Moq (and/or maybe something else) for the purpose that I've described above. Punjab kesari epaper himachal news. Note: serial computing has a number of issues, random data loss is possible in this particular situation but the most likely issues may be related to timing and timeouts; example, a human might be using the related non computer device while the specialized 'computer' is attempting to respond to requests via its serial port. Any ideas would be appreciated. Regards, Gerry David K Allen - Minneapolis, MN 26.11.10 9:04.
It is precisely these kinds of situations, where the real hardware/software are not easily available or tested that mocks are valuable. Are you experienced with using mocks in more mundane situations? Do you have experience with other mocking frameworks or tools? Have you used TDD before?
I'm trying to understand whether you are asking about mocking and testing in general or MOQ in particular. David Kreth Allen On Fri, Nov 26, 2010 at 10:43 AM, gerrylowry alliston ontario canada 705 250-0112 wrote: - Post: Unsubscribe: - David Kreth Allen gerryLowry 26.11.10 9:26. Hello David, I've too little experience with Moq, which I've chosen because the source is available and because Moq is written in c# and has had great reviews. Also, the fact that Daniel chose xUnit.net to unit test Moq was a strong initial factor in my looking at Moq versus alternatives.
My use of Moq is very limited to date, mostly with MVC development. Perhaps I'm over complicating this?
As described below, serial port data flow appears to me to be a bit more challenging because of timing issues that are much less likely in a RESTful MVC environment. P.S.: I had done quite a bit of research around Moq but then was not allowed by my employer at the time to even use xUnit.net or any unit testing period in their WebForms environment; for that reason, I'm quite rusty and busy trying to 'get it' with regards to mocking in general and Moq in particular.
Original Message - David Kreth Allen To: Sent: Friday, November 26, 2010 12:04 PM Subject: Re: Moq how does one Moq a serial port? Gerry Lowry, Partner Alliston � Ontario � Canada � L9R 0E1 � 705.250.0112 David K Allen - Minneapolis, MN 26.11.10 18:04. You cannot use MOQ to mock SerialPort directly. It is a concrete class without virtual methods. I see two ways around this obstacle: either buy TypeMock, which can mock many more things than MOQ can, or you create your own interface ISerialPort and use the adapter pattern to wrap a real serial adapter and implement the interface.
Then you can code to the interface, which is the preferred practice anyway, to provide isolation and testability. Then you can MOQ the interface quite easily. The adapter approach is the one I would use because I would not want to buy TypeMock. Your choice may be different.
C Serial Port Code
Either way, this challenge is solved. If you have any doubts what this looks like, I pasted a simplified version below. It's worthwhile for others to have because this is such a common challenge. And people do not always think to take this approach. They simply say 'I can't mock this so I give up.' The harder part is understanding how your device will work in practice.
You cannot simulate something you do not understand. If you have complete and reliable description of the device under test in all scenarios of interest, and they specify exactly what signals you send, and how data flows, then you are very lucky. More likely, you do not have that. You will have to get access to the real device for an extended period of time. At this point, you have lots of hard choices.
But all of them involve playing with the device and learning what it will spit out under different scenarios. I can't imagine any easier way to do it. I'm sure you were expecting to do this anyway, right? As I mentioned above, MOQ can easily mock an interface, no matter how complex. Coping with exception cases like missing data, timeouts, etc. Are all easy problems to solve. The hard part of your problem is doing enough coding and testing with the real device to understand it's behavior well enough to simulate it.