Basically, you can't - not in practice. What you need to create is a device driver which pretends to be a com port, and those aren't simple, not at all.
If you want this to test your software, then I'd strongly suggest that you do go third party, or, use a second port on your machine via a "null modem cable" to provide the device emulation.
For third party:
com0com[
^] seems popular, but I haven't used it myself.
For cable:
Testing Serial Application with Virtual Ports[
^]