开发测试数据-通过API批量生成
Posted 超香Q的五香卤猪脚
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了开发测试数据-通过API批量生成相关的知识,希望对你有一定的参考价值。
参考网址
背景
在日常开发过程中,可能需要一些批量的用户数据,方便开发与测试。
Random User是一个基于Web 的api服务
从网址上就能理解,它是用来帮我们生成用户信息的。
简单使用
调用api
https://randomuser.me/api/
在浏览器上输入url,并打开
{ "results": [{ "gender": "female", "name": { "title": "Ms", "first": "Tilde", "last": "Petersen" }, "location": { "street": { "number": 8318, "name": "Kirkebakken" }, "city": "Lemvig", "state": "Sjælland", "country": "Denmark", "postcode": 50849, "coordinates": { "latitude": "-34.1827", "longitude": "137.6308" }, "timezone": { "offset": "-8:00", "description": "Pacific Time (US & Canada)" } }, "email": "tilde.petersen@example.com", "login": { "uuid": "fcc2d67b-7d8f-42b6-88af-defe45d7000b", "username": "whiteswan915", "password": "passion", "salt": "2H0kQxHI", "md5": "72caa139078114cf132c550ffb570a45", "sha1": "32fd9aeeff2048a652ec0a7c3f615b88a844b493", "sha256": "3780104e9ee8ab6c6a16ee95b99aa9c24ba666f42c2417bfad4e118850469df2" }, "dob": { "date": "1998-01-21T06:47:48.526Z", "age": 23 }, "registered": { "date": "2017-07-26T18:22:10.588Z", "age": 4 }, "phone": "38400064", "cell": "81108424", "id": { "name": "CPR", "value": "210198-6685" }, "picture": { "large": "https://randomuser.me/api/portraits/women/27.jpg", "medium": "https://randomuser.me/api/portraits/med/women/27.jpg", "thumbnail": "https://randomuser.me/api/portraits/thumb/women/27.jpg" }, "nat": "DK" }], "info": { "seed": "072ef5473530b525", "results": 1, "page": 1, "version": "1.3" } }
获取多个用户数据
默认是一个,要想获得多个用户数据,需要加上参数
result=[num]
例如:
https://randomuser.me/api/?results=5
{ "results": [{ "gender": "male", "name": { "title": "Mr", "first": "Tyler", "last": "Day" }, "location": { "street": { "number": 5487, "name": "Nowlin Rd" }, "city": "Gladstone", "state": "Queensland", "country": "Australia", "postcode": 6425, "coordinates": { "latitude": "-88.8425", "longitude": "-176.8110" }, "timezone": { "offset": "-8:00", "description": "Pacific Time (US & Canada)" } }, "email": "tyler.day@example.com", "login": { "uuid": "f3288663-248b-40b1-8e62-dc34cb90dfba", "username": "happycat858", "password": "tigers", "salt": "isISaSeW", "md5": "c9615397692029e75eb5689e08f28c98", "sha1": "e765869b24cad1f5eb43af736fdc94673716565e", "sha256": "c9187858e768ce7d7190df5dc1e378152a9cdd9f161e311c9dc574db0e0a2eaf" }, "dob": { "date": "1985-06-22T07:43:07.898Z", "age": 36 }, "registered": { "date": "2005-10-21T16:26:16.194Z", "age": 16 }, "phone": "07-6508-9663", "cell": "0447-236-528", "id": { "name": "TFN", "value": "305352099" }, "picture": { "large": "https://randomuser.me/api/portraits/men/29.jpg", "medium": "https://randomuser.me/api/portraits/med/men/29.jpg", "thumbnail": "https://randomuser.me/api/portraits/thumb/men/29.jpg" }, "nat": "AU" }, { "gender": "male", "name": { "title": "Mr", "first": "Erique", "last": "Ramos" }, "location": { "street": { "number": 2427, "name": "Rua Paraná " }, "city": "Corumbá", "state": "Mato Grosso", "country": "Brazil", "postcode": 66605, "coordinates": { "latitude": "-34.4406", "longitude": "-10.3198" }, "timezone": { "offset": "+7:00", "description": "Bangkok, Hanoi, Jakarta" } }, "email": "erique.ramos@example.com", "login": { "uuid": "b45a93d5-0858-431e-aa11-5dd3746aa368", "username": "yellowfish417", "password": "pressure", "salt": "NpyFmsPt", "md5": "ea719424c8a40a9c100672bc9d63f468", "sha1": "1641593df865e2e852a829fa031ebe822a5ba76c", "sha256": "2c386b46f332959332a02a9c61cffd442f4dd0c058d5ad6f8bd39081b2013272" }, "dob": { "date": "1959-06-16T14:50:16.957Z", "age": 62 }, "registered": { "date": "2010-05-27T06:46:06.128Z", "age": 11 }, "phone": "(96) 6463-3144", "cell": "(12) 6911-1925", "id": { "name": "", "value": null }, "picture": { "large": "https://randomuser.me/api/portraits/men/79.jpg", "medium": "https://randomuser.me/api/portraits/med/men/79.jpg", "thumbnail": "https://randomuser.me/api/portraits/thumb/men/79.jpg" }, "nat": "BR" }, { "gender": "male", "name": { "title": "Mr", "first": "Mathias", "last": "Olsen" }, "location": { "street": { "number": 2113, "name": "Rypevej" }, "city": "Kvistgaard", "state": "Nordjylland", "country": "Denmark", "postcode": 71740, "coordinates": { "latitude": "-55.0795", "longitude": "-72.1922" }, "timezone": { "offset": "-8:00", "description": "Pacific Time (US & Canada)" } }, "email": "mathias.olsen@example.com", "login": { "uuid": "a5bf4547-cfaa-46a4-8377-24af232e3850", "username": "organicpanda228", "password": "1215", "salt": "XHMOcCmj", "md5": "6795b3cda59327742f12ac645d27ec96", "sha1": "9731ac7e188179dbc83f99faf628dfe864acf47a", "sha256": "ba8597aa56351284eb4e9264b95dfb215667cb3a8bfc469781245f254e46c3b9" }, "dob": { "date": "1989-03-19T12:30:16.872Z", "age": 32 }, "registered": { "date": "2013-12-13T04:08:04.259Z", "age": 8 }, "phone": "55430896", "cell": "67029580", "id": { "name": "CPR", "value": "190389-7286" }, "picture": { "large": "https://randomuser.me/api/portraits/men/16.jpg", "medium": "https://randomuser.me/api/portraits/med/men/16.jpg", "thumbnail": "https://randomuser.me/api/portraits/thumb/men/16.jpg" }, "nat": "DK" }, { "gender": "female", "name": { "title": "Ms", "first": "Emilia", "last": "Karjala" }, "location": { "street": { "number": 4240, "name": "Rotuaari" }, "city": "Punkaharju", "state": "Southern Savonia", "country": "Finland", "postcode": 22728, "coordinates": { "latitude": "18.9856", "longitude": "59.1125" }, "timezone以上是关于开发测试数据-通过API批量生成的主要内容,如果未能解决你的问题,请参考以下文章