javascript - 我是否需要测试前端客户端应用程序进行的实际 API 调用?
问题描述
我对 C# 和 JavaScript 比较陌生,我正在制作一个 ASP.NET/React/Redux 应用程序。我使用 superagent 编写了一个简单的 HTTP 发布请求:
import request from "superagent";
export const authenticationService = {
login
};
function login(email, password) {
return request.post("http://localhost:55903/api/login/contractor")
.type("form")
.send({ EmailAddress: email})
.send({ Password: password })
.then((res) => {
return res;
})
.catch((err) => {
return err;
});
};
我的主要问题是我是否需要对实际登录功能本身进行单元测试?到目前为止,我只看到了一些模拟 HTTP 响应来测试 React/Redux 方面的示例,但我还没有看到测试上述 HTTP 请求函数的示例。
解决方案
在您的情况下,在前端最好模拟数据,因为您不是在测试 HTTP 请求,而是在测试您的 React 应用程序是否显示正确的内容。
然而,应该在后端测试 HTTP 请求。所以你的登录请求测试应该用你的 C# 代码而不是你的 React/Redux 代码。
推荐阅读
- swift - 在关联类型对象上使用 KeyPaths
- javascript - 在此示例中,如何将数组对象与正则表达式匹配?
- azure-web-app-service - 无法使用 MSI 实现对 azure 存储容器 (blob) 的 azure Web 应用服务访问
- mininet - Iperf 客户端在使用 TCLinks 的 Mininet 中报告吞吐量过高
- android - 如何通过将键设置为字符串来使用recyclerview-selection?
- java - 在 JTable 中添加 JSpinner 时出现非法参数异常
- node.js - express-session - 会话 id 和 connect.sid 之间的区别?
- c - 为什么我的 AVL 平衡函数会丢失数据?
- docker - ASP.NET Core Docker 容器应用程序无法访问
- html - 如何更好地处理 HTML 标签之间的正则表达式捕获组?