在线抽奖系统——项目测试
目次测试用例
功能测试
界面测试
自动化测试
性能测试
总结
测试用例
https://i-blog.csdnimg.cn/direct/0bbe253fe76c4332906ec77cb1f7831e.png
功能测试
下面以 注册功能 测试为例进行展示:
https://i-blog.csdnimg.cn/direct/e371cf79323840d281667d59916454dc.png
正常注册:
以 姓名:王五 邮箱:1342111111@qq.com 手机号:13421111111 暗码:1342111111 为例进行注册:
https://i-blog.csdnimg.cn/direct/37e818c330094fd7b26573e946bf408f.png
点击注册:
https://i-blog.csdnimg.cn/direct/afdba46d6bf245e9b502cf0b6ab1893e.png
输入姓名、邮箱、手机号和暗码,点击注册按钮后,页面会提示 "注册成功,去登录" ,正常注册情况下功能正常
非常注册:
非常注册重要从以下角度进行测试:
1. 用户名非常:用户名为空
2. 邮箱非常
a. 邮箱为空
b. 邮箱格式错误
c. 邮箱已存在
3. 手机号非常:
a. 手机号为空
b. 手机号格式错误
c. 手机号已存在
4. 暗码非常:
a. 暗码为空
b. 暗码长度格式错误
c. 暗码中包罗特殊字符
未填写完注册信息,直接点击注册:
https://i-blog.csdnimg.cn/direct/58562a72038d40699dccc138740792c7.png
https://i-blog.csdnimg.cn/direct/4a9fdec102cb43b2bc41564e124865a5.png
页面会提示对应信息未输入
邮箱格式错误:
https://i-blog.csdnimg.cn/direct/6d17356253ce4327bccf515d2073cfeb.png
邮箱已存在:
https://i-blog.csdnimg.cn/direct/13c95ba267f84d97a69943f938e6de45.png
手机号格式错误:
https://i-blog.csdnimg.cn/direct/aaa9ebf45a5b4f5c90859683b540e1ee.png
手机号已存在:
https://i-blog.csdnimg.cn/direct/b69da2fe8097421f8616d36133042177.png
暗码过长(大于 12 位):
https://i-blog.csdnimg.cn/direct/0d790c822f3648389b0763dcaf7cbb8b.png
暗码过短(小于 6 位):
https://i-blog.csdnimg.cn/direct/81f6419105414a2ab16b5bf63d8aa8b0.png
暗码中包罗特殊字符:
https://i-blog.csdnimg.cn/direct/6bf04d69c4f24539b928d785dcd91163.png
非常注册情况下,会提示对应的非常信息
通过测试,在注册页面并未发现 bug
界面测试
以 登录页面 测试为例进行展示:
https://i-blog.csdnimg.cn/direct/8b3e1398f4d5478e95cbe185a8bf7fe4.png
https://i-blog.csdnimg.cn/direct/caeb09bcc9294ea48748803beb97c0f1.png
登录页面图片、按钮以及输入框正常显示,提示信息正确,无错别字,无关键信息遮挡情况
https://i-blog.csdnimg.cn/direct/2deff67e9ebb46a89380f1f3faa494d9.png
暗码登录和验证码登录之间可以或许正确切换,验证码登录按钮、输入框正确显示
https://i-blog.csdnimg.cn/direct/f9fa00b774494556ba63ba703eb8f657.png
压缩情况下,图片不再显示,仅显示登录信息
https://i-blog.csdnimg.cn/direct/ede60234af8f4d1ab184d0540c3cd9fb.png
https://i-blog.csdnimg.cn/direct/b0310b988db64986956768cd576c6d72.png
注册链接正确显示,可以或许跳转到注册页面
自动化测试
以 职员列表 为例进行演示:
引入依赖:
<dependencies>
<!-- selenium -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0</version>
</dependency>
<!-- 驱动管理-->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.5.3</version>
</dependency>
<!-- 屏幕截图-->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies> 我们创建 Utils 类,用于存放自动化代码中的通用方法:
public class Utils {
public static WebDriver webDriver;
/**
* 创建 webDriver 并 访问指定 url
* @param url
*/
public Utils(String url) {
if (null == webDriver) {
WebDriverManager.edgedriver().setup();
EdgeOptions options = new EdgeOptions();
// 允许访问所有连接
options.addArguments("--remote-allow-origins=*");
this.webDriver = new EdgeDriver(options);
// 隐式等待 3 秒
this.webDriver.manage().timeouts().implicitlyWait(java.time.Duration.ofSeconds(3));
}
webDriver.get(url);
}
/**
* 关闭 WebDriver 和浏览器
*/
public void closeBrowser() {
if (webDriver != null) {
webDriver.quit();
}
}
/**
* 进行屏幕截图并将其保存到自定路径
* 路径: ./src/tests/image/2025-2-24/LoginPage-17548130.png
* @param str
*/
public void getScreenShot(String str) {
try {
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HHmmssSS");
String dirTime = dateFormatter.format(LocalDateTime.now());
String fileTime = timeFormatter.format(LocalDateTime.now());
// 使用 File.separator 来适应不同操作系统上的路径分隔符
String filename = "src" + File.separator + "test" + File.separator + "image" + File.separator + dirTime + File.separator + str + "-" + fileTime + ".png";
// 创建目录
Path path = Paths.get(filename).getParent();
if (path != null && !Files.exists(path)) {
Files.createDirectories(path);
}
// 将截图存放到指定位置
File srcFile = ((TakesScreenshot)webDriver).getScreenshotAs(OutputType.FILE);
File destFile = new File(filename);
FileUtils.copyFile(srcFile, destFile);
} catch (IOException e) {
// 更好的错误处理或日志记录
System.err.println("截图失败: " + e.getMessage());
e.printStackTrace();
}
}
} 对职员列表页进行测试:
public class UserListPage extends Utils {
private static String url = "http://49.108.48.236:8080/user-list.html";
public UserListPage() {
super(url);
}
/**
* 未登录状态下访问人员列表页
*/
public void noLoginToUserListPage() {
// 处理弹窗
WebDriverWait wait = new WebDriverWait(webDriver, Duration.ofSeconds(5));
wait.until(ExpectedConditions.alertIsPresent());// 等待弹窗出现
Alert alert = webDriver.switchTo().alert();
alert.accept();
// 判断是否返回到登录页面
String expect = webDriver.getTitle();
assert expect.equals("管理员登录页面");
}
/**
* 检查人员列表页是否加载成功
*/
public void userListPageRight() {
// 1. 进行登录
webDriver.findElement(By.cssSelector("#phoneNumber")).clear();
webDriver.findElement(By.cssSelector("#password")).clear();
webDriver.findElement(By.cssSelector("#phoneNumber")).sendKeys("13311111111");
webDriver.findElement(By.cssSelector("#password")).sendKeys("13311111111");
webDriver.findElement(By.cssSelector("#loginForm > button")).click();
// 2. 等待页面加载
WebDriverWait wait = new WebDriverWait(webDriver, Duration.ofSeconds(5));
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#userList")));
// 3. 导航到人员列表页
webDriver.findElement(By.cssSelector("#userList")).click();
// 4. 查看列表元素
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#userList")));
getScreenShot(getClass().getName());
}
} 进行测试:
public class RunTest {
public static void main(String[] args) {
UserListPage userListPage = new UserListPage();
userListPage.noLoginToUserListPage();
userListPage.userListPageRight();
userListPage.closeBrowser();
}
} 测试通过;
https://i-blog.csdnimg.cn/direct/378f0407064a45dd970e9d6859546754.png
性能测试
利用 JMeter 对 管理员暗码登录接口、获取职员列表接口、获取奖品列表接口 以及 获取活动列表接口 进行性能测试:
https://i-blog.csdnimg.cn/direct/eda8c2cf981741f384857e46efd6224a.png
聚合报告:
https://i-blog.csdnimg.cn/direct/74166ec82f1a45d8b8f9f8db22cca6e0.png
结果分析:
1. 全部接口的非常率为0%,且相应时间较为稳定,说明系统在当前并发场景下具有良好的稳定性和可靠性
2. 总体吞吐量到达361.4/sec,单个接口的吞吐量也都在90次/秒以上,表明系统在当前并发场景下具备较强的处置处罚本领
相应时间:
https://i-blog.csdnimg.cn/direct/57f20187dcef4b8b8f9bb04f10f019ea.png
结果分析:
1. 管理员暗码登录接口的相应时间颠簸较大,平均在75 ms左右
2. 获取职员列表、奖品列表和活动列表接口的相应时间相对稳定,平均在43 ms左右
每秒处置处罚事务数:
https://i-blog.csdnimg.cn/direct/084bb7166a284806843d30447e27c484.png
结果分析:
1. 在测试过程中,每秒处置处罚事务数基本保持在90次左右,说明系统在当前并发情况下仍能保持较高的处置处罚本领
2. 接近测试竣事时,TPS有显着下降趋势,这是由于线程数目逐渐淘汰导致的
活泼线程数:
https://i-blog.csdnimg.cn/direct/1d4ccb99a28a4a33a996e3c1d5081500.png
结果分析:
1. 测试开始后,线程数目敏捷上升至20个,并在大部门时间内保持稳定
2. 接近测试竣事时,线程数目逐渐淘汰,终极降至0,表明全部线程任务完成并退出
总结
功能测试:
1. 在线抽奖系统的基本功能正常运行,正常流程可以或许正确实行
2. 用户进行抽奖时相应及时,可以或许对抽奖过程中的非常情况进行处置处罚
3. 在进行抽奖关照时,仅利用 qq 邮箱进行关照,可对其进行优化,使系统支持多种邮箱关照以及验证码关照
界面测试:
1. 全部按钮点击相应及时,页面显示良好,无错别字,无遮挡或显示错误情况
2. 对于非常情况都利用弹窗进行提示,对用户体验不友好,可利用自界说模态框、表单验证反馈等进行提示
性能测试:
1. 该系统的性能测试结果表明其在当前并发场景下表现良好,可以或许满意需求
2. 后续可调整测试设置,增加线程数或调整循环次数,以测试更高并发用户数下性能
其他改进点:
1. 客户端发送的手机号和暗码在网络中明文传输,应对其进行加密
2. 添加奖品信息修改删除功能以及职员信息修改删除功能
3. 限制单个用户的抽奖次数和频率,防止恶意刷奖
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]