How to test QUdpSocket object
-
I'm writing an object to send data via udp to a statsd endpoint. I have the the sendUDP method written and it returns the number of bytes sent so I can test the length of the data against the length sent in my unit test.
Is there a way for the unit test to set up a udp socket client and verify the data arrives. I understand that UDP is not guaranteed delivery. But, in a unit test between a machine and itself, it should be generally reliable. I'm just exploring the options.
The challenge in what I've looked at before is that the receiving is done via sockets and signals and is out-of-line from the unit test that sends the data.
Any suggestions or hints would be appreciated.
-
You're looking for https://doc.qt.io/qt-5/qtest.html#qWaitFor
-
@dwilliams said in How to test QUdpSocket object:
Is there a way for the unit test to set up a udp socket client and verify the data arrives. I understand that UDP is not guaranteed delivery. But, in a unit test between a machine and itself, it should be generally reliable. I'm just exploring the options.
ncat utility...
https://serverfault.com/questions/207683/listen-to-udp-data-on-local-port-with-netcat
and if the data is binary then pipe the output to "od -cx"
-
@Kent-Dorfman said in How to test QUdpSocket object:
ncat utility...
In an unit test? Not very useful....
-
by the wikipedia defintiion of unit testing I don't see a problem.
In computer programming, unit testing is a software testing method by which individual units of source code, sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures, are tested to determine whether they are fit for use.