How do I do unit tests for code using system objects?

That's probably a bad title, let's try with specifics: we have a network extension, it has some classes / functions of its own, and they, when push comes to build, depend on (for example) NEAppProxyFlow and its subclasses. The code is written in Swift, since it is the language of the future.

If I want to do a unit test for my code, I need to provide something that at least looks like NEAppProxyFlow, since I can't otherwise create one. I thought I could provide my own NetworkExtension module for test case, but that... did not work well, and I still don't understand why.

On the other hand, I'm really bad at making unit tests, so the odds that I'm missing something fairly obvious to most other people are pretty high.

For an answer to your question, see this thread: https://developer.apple.com/forums/thread/749579.

For additional information, watch 2018 WWDC Testing Tips & Tricks and read Updating your existing codebase to accommodate unit tests.

Matt Easton over at https://forums.developer.apple.com/forums/thread/756508 said otherwise -- specifically,

For example, your flow copying logic relies on NEAppProxyFlow objects, but you could mock up a test object that represents the infrastructure in this class to just pipe network traffic into it to exercise your flow copying logic.

If it were in ObjC, I could do #if and/or #define tricks to include different headers, but I don't know how I'd do that with Swift. (And I can never remember how to define something in build settings or the command line and have Swift able to use #if for it, so I always have to go searching for it again.)

How do I do unit tests for code using system objects?
 
 
Q