开发者

Testing against an external UDP API. Where to start?

I'm writing a client library against an API that communicates using UDP through a socket connection. I'm trying to write tests as I go however I'm running into a few problems.

  • Should I just build a testing server and start that up in my test helper? I don't want to hammer the external servers when running my tests.
  • Or should I just mock the hell out of the UDPSocket lib and test against that?

My problem with the first option is that I then have to keep up with changes to the API and make sure that my dummy server emulates them, which could lead to false positives and brittle tests. And my problem with 2 is that excessive mocking could also lead to brittle tests in case anything in UDPSocket changes.

However I开发者_如何学编程've been spiking on this for a couple of days now and having big gaps of missing test coverage is making me a bit nervous. What would you do?

thanks


I tend to mock this sort of thing. Anytime you're communicating with an external host, you probably want to mock. It doesn't make a whole lot of sense for your unit tests to be dependent on internet connectivity.

I would also advise against going to the trouble of making a sophisticated emulated server. Mocking is pretty much the same thing, without having to write the logic. Either way, you're not going to be talking to The Real Thing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜