我正在为 Django-rest-framework API 端点编写单元测试。在 version 3.5 中,他们添加了 RequestsClient()。文档说——
Rather than sending any HTTP requests to the network, this interface will coerce all outgoing requests into WSGI, and call into your application directly.
根据我的理解,我认为 RequestsClient() 对于来自不同服务器的网络请求很有用。不知道在同一台服务器上有没有什么优势?另外,使用 RequestsClient() 比 APIClient() 有什么优势吗?
最佳答案
如果您不确定,请使用标准 APIClient
。RequestsClient
在以下情况下很有用:
关于unit-testing - 与 APIClient() 相比,使用 RequestsClient() 有什么优势?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40488339/