在Debian系统上进行API测试,首先需要安装Postman。以下是几种在Debian上安装Postman的方法:
sudo apt update
sudo apt install snapd
sudo snap install postman
snap run postman
来启动。下载Postman安装包:
解压安装包:
wget https://dl.pstmn.io/download/latest/linux64 -O postman.tar.gz
sudo tar -xzf postman.tar.gz -C /opt
rm postman.tar.gz
创建软链接:
sudo ln -s /opt/Postman/Postman /usr/local/bin/postman
创建桌面启动项:
postman.desktop
的文件,并将其保存在 ~/.local/share/applications/
目录下:nano ~/.local/share/applications/postman.desktop
在文件中添加以下内容(确保路径正确):
[Desktop Entry]
Encoding=UTF-8
Name=Postman
Exec=/usr/local/bin/postman
Icon=/opt/Postman/app/resources/app/assets/icon.png
Terminal=false
Type=Application
Categories=Development;
赋予执行权限:
chmod +x ~/.local/share/applications/postman.desktop
从应用菜单启动Postman:
创建安装脚本:
install-postman.sh
的脚本文件,并添加以下内容:#!/bin/bash
cd /tmp || exit
echo "Downloading Postman ..."
wget -q https://dl.pstmn.io/download/latest/linux?arch=64 -O postman.tar.gz
tar -xzf postman.tar.gz
rm postman.tar.gz
echo "Installing to opt..."
if [ -d "/opt/Postman" ];then
sudo rm -rf /opt/Postman
fi
sudo mv Postman /opt/Postman
echo "Creating symbolic link..."
if [ -L "/usr/bin/postman" ];then
sudo rm -f /usr/bin/postman
fi
sudo ln -s /opt/Postman/Postman /usr/bin/postman
echo "Installation completed successfully."
echo "You can use Postman!"
给脚本文件执行权限并运行它:
chmod +x install-postman.sh
./install-postman.sh
安装Snapd服务(如果尚未安装):
sudo apt update
sudo apt install snapd
添加Postman的官方PPA:
sudo add-apt-repository https://dl.bintray.com/postman/apt
更新软件包列表:
sudo apt update
安装Postman:
sudo apt install postman
创建请求:
设置参数:
发送请求:
验证响应:
编写测试脚本:
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Response contains userId", function () {
var jsonData = pm.response.json();
pm.expect(jsonData).to.have.property('userId');
});
运行测试:
通过以上步骤,你可以在Debian系统上成功安装并配置Postman,并使用它进行API测试。