Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I (unit)test the CaptureDevices? #279

Open
NeoMorfeo opened this issue May 7, 2021 · 3 comments
Open

How can I (unit)test the CaptureDevices? #279

NeoMorfeo opened this issue May 7, 2021 · 3 comments

Comments

@NeoMorfeo
Copy link

I wish to knwo if there is any way to mock the CaptureDevices (CaptureDeviceList).

I need that to test several code, that relays on the detection of the devices, but, i can't make a mock or substitute.

Can you provide some info about it?

thanks in advance.

@roberdcr
Copy link

roberdcr commented May 7, 2021

Thanks @NeoMorfeo for this post! I think we need a way to test our code and due to it doesn't use interfaces it is so hard to have a nice way to test

@chmorgan
Copy link
Collaborator

chmorgan commented May 7, 2021

@kayoub5 and I have discussed dropping the singleton use in CaptureDeviceList etc but changes here on master have yet to be made. Suggestions for improvements are welcome. 6.x is coming soon so now is a good time to propose API altering changes.

@kayoub5
Copy link
Collaborator

kayoub5 commented May 7, 2021

The way I see it, we already have the PcapInterface.GetAllPcapInterfaces(), and a single class for PCAP device new LibPcapLiveDevice(PcapInterface pcapIf), so the CaptureDeviceList could be removed as far as I see.

For the original request, You can:

  • Mock a single device by mocking the ICaptureDevice
  • Mock a list of devices by mocking the base class of CaptureDeviceList: ReadOnlyCollection<> (the application should use a List of CaptureDevice instead of directly referencing CaptureDeviceList.Instance)
  • Create your own C library wpcap.dll or libpcap.so

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants