Linefinc
Linefinc

Reputation: 383

Test unit with embedded application with .NET

I wrote an application that run on windows embedded. The app read data from different serial ports, make some data analysis and send data to another machine, primarily db.

The application is growed drastically in the last period and we need add some Test Unit to reduce the physical testing phase.

Now, I need some suggest to understand how to emulate the serial port and what’s the correct way to emulate a external device. A small issues is due to some timer inside the code to bouncing effect, what I have to do? made a special build without De-Bouncing timer?

At the same times, the code is wroten as a big Finite State Machine , it's quity simple to test a single state but the interaction bwtween the states?

Best regards

Upvotes: 0

Views: 57

Answers (1)

What I usually do is to make a class who's whole purpose is to interact with the external device, and I make it implement an interface.

public interface IExternalDeviceInteractor
{
    string GetAStringFromTheDevice();
}

public class ExternalDeviceInteractor : IExternalDeviceInteractor
{
    public string GetAStringFromTheDevice()
    {
        //interact with device here
    }
}

Then, I make a class, which implements the interface, and just spits out test data.

public class MockExternalDeviceInteractor : IExternalDeviceInteractor
{
    public string GetAStringFromTheDevice()
    {
        return "StringForTesting";
    }
}

Upvotes: 3

Related Questions