Postman在Ubuntu上的安装方式主要有三种,推荐使用Snap安装(最便捷)或手动下载安装包(适合需要特定版本的用户)。
Snap是Ubuntu的软件包管理工具,安装Postman只需几步:
Ctrl+Alt+T
),更新系统并安装Snapd(若未安装):sudo apt update && sudo apt upgrade -y
sudo apt install snapd
sudo snap install postman --classic
若需要特定版本的Postman,可通过以下步骤手动安装:
Postman-linux-x64-7.6.0.tar.gz
)。/opt
目录(系统级软件目录):cd ~/Downloads
sudo tar -xzf Postman-linux-x64-7.6.0.tar.gz -C /opt/
postman
):sudo ln -s /opt/Postman/Postman /usr/bin/postman
/usr/share/applications/postman.desktop
文件,内容如下:[Desktop Entry]
Encoding=UTF-8
Name=Postman
Exec=/opt/Postman/Postman
Icon=/opt/Postman/app/resources/app/assets/icon.png
Terminal=false
Type=Application
Categories=Development;
赋予可执行权限:sudo chmod +x /usr/share/applications/postman.desktop
postman
或从应用菜单打开。安装完成后,即可通过Postman进行API请求、响应验证及自动化测试。
https://api.example.com/users
)。Content-Type: application/json
);raw
模式并设置为JSON
格式,输入请求体(如{"name": "John", "age": 30}
);?page=1&limit=10
)。Postman支持通过JavaScript编写测试脚本,验证API响应是否符合预期。
// 验证状态码是否为200
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
// 验证响应体是否包含特定字段(假设返回JSON)
pm.test("Response contains user data", function () {
const jsonData = pm.response.json();
pm.expect(jsonData).to.have.property("id");
pm.expect(jsonData).to.have.property("name");
});
// 验证响应时间是否小于200ms
pm.test("Response time is less than 200ms", function () {
pm.expect(pm.response.responseTime).to.be.below(200);
});
为便于管理多个相关请求,可将它们保存到**集合(Collection)**中:
若测试环境需要通过代理访问API,可在Postman中配置代理:
http://proxy.example.com
)和端口号(如8080
)。通过以上步骤,即可在Ubuntu系统下使用Postman完成API测试的全流程,包括请求发送、响应验证、自动化测试及团队协作(通过集合共享)。Postman的图形化界面降低了API测试的学习成本,适合开发人员、测试人员及API使用者使用。