Unit Testing .... data provider?

This problem:

  • I like unit tests.
  • I develop software for connecting to external systems, which quite often and often use the C ++ library.
  • The return of these systems is not deterministic. Data is received during operation, but making sure that all this is correctly interpreted is difficult.

How can I check this correctly?

I can run the unit test, which makes the connection. Unfortunately, it will process the data stream of life. I can say that I run the test for 30 or 60 seconds before disconnecting, but getting the ccoverage code is not possible - I'm just not going to get all the code codes EVERYTHING FORWARD (code error codes are rarely executed). I also cannot claim every result. Depending on the time of day, we are talking about 20,000 data callbacks per second - all of them cannot be defined well enough to check each of them for consistency. Tantalizing? Well, that would leave me testing the empty shell myself, because the code that handles the events is basically a proven case, and in many cases we are talking here about the COMPLEX c level structure - it's hard to have mocking frameworks,which integrate from Csharp to C ++

Any idea? I cannot refuse to use unit tests for this part of the application.

+3
source share
2 answers

Testing the device is good, but it should not be your only weapon against errors. See the difference between unit tests and integration tests : it sounds to me like the latter is your best bet.

In addition, automated tests (unit tests and integration tests) are only useful if the behavior of your system does not change. If you break backward compatibility with each version, automatic tests of this function will not help you.

You can also see the previous discussion of how many testing units are too many .

+3
source

- , , . , ​​ mock.

public interface IDataSource
{
     public List<DataObject> All();
     ...
}

public class DataWrapper : IDataSource
{
     public DataWrapper( RealDataSource source )
     {
         this.Source = source;
     }

     public RealDataSource Source { get; set; }

     public List<DataObject> All()
     {
          return this.Source.All();
     }
}

, mock, .

public void DataSourceAllTest()
{
    var dataSource = MockRepository.GenerateMock<IDataSource>();
    dataSource.Expect( s => s.All() ).Return( ... mock data ... );

    var target = new ClassUnderTest( dataSource );

    var actual = target.Foo();

    // assert something about actual

    dataSource.VerifyAllExpectations();
}
0

Source: https://habr.com/ru/post/1782527/


All Articles