Sometimes the weirdest things come up when testing. I was helping with some
Integration Testing recently, and we needed to submit a new valid postal address with
every request to this system. That’s a hefty load to bear, and certainly if
I were doing Unit Testing I’d be mocking away that system just to not have to deal
with that problem, but for Integration Tests there was no way around it. My
answer? Public data my good friends.
The quest started with Google, as most do, and a search criteria like this :
City State Zip filetype:csv
Which after browsing for several pages I modified to:
City State Zip filetype:csv site:usps.com
That resulted in the CSV which is the source of the data we’re using, a list of Post
Offices across the nation. The list is very long, a total of 19,931 addresses.
Now, it wouldn’t be fair to just list the Google queries here, after all this is a
technical blog. I took the CSV apart, removed the irrelevant fields and parsed
it into an object to hold address data, specifically this object.
Now if you compile your own version of that code, and create a List<AddressData>
you should be able to Deserialize
this file of all the addresses for your own use.