在线抽奖系统——项目测试

打印 上一主题 下一主题

主题 833|帖子 833|积分 2499

目次

测试用例
功能测试
界面测试
自动化测试
性能测试
总结


测试用例



功能测试

下面以 注册功能 测试为例进行展示:

正常注册:
 姓名:王五 邮箱:1342111111@qq.com 手机号:13421111111 暗码:1342111111  为例进行注册:

点击注册:

输入姓名、邮箱、手机号和暗码,点击注册按钮后,页面会提示 "注册成功,去登录" ,正常注册情况下功能正常

非常注册:
非常注册重要从以下角度进行测试:
   1. 用户名非常:用户名为空
  2. 邮箱非常
          a. 邮箱为空
          b. 邮箱格式错误
          c. 邮箱已存在
  3. 手机号非常:
          a. 手机号为空
          b. 手机号格式错误
          c. 手机号已存在
  4. 暗码非常:
          a. 暗码为空
          b. 暗码长度格式错误
          c. 暗码中包罗特殊字符
  未填写完注册信息,直接点击注册:


页面会提示对应信息未输入
邮箱格式错误:

邮箱已存在:

手机号格式错误:

手机号已存在:

暗码过长(大于 12 位):

暗码过短(小于 6 位): 

暗码中包罗特殊字符:

非常注册情况下,会提示对应的非常信息
通过测试,在注册页面并未发现 bug

界面测试

登录页面 测试为例进行展示:


登录页面图片、按钮以及输入框正常显示,提示信息正确,无错别字,无关键信息遮挡情况


暗码登录和验证码登录之间可以或许正确切换,验证码登录按钮、输入框正确显示
 

压缩情况下,图片不再显示,仅显示登录信息


注册链接正确显示,可以或许跳转到注册页面

自动化测试

职员列表 为例进行演示:
引入依赖:
  1.     <dependencies>
  2.         <!--        selenium -->
  3.         <dependency>
  4.             <groupId>org.seleniumhq.selenium</groupId>
  5.             <artifactId>selenium-java</artifactId>
  6.             <version>4.0.0</version>
  7.         </dependency>
  8.         <!--        驱动管理-->
  9.         <dependency>
  10.             <groupId>io.github.bonigarcia</groupId>
  11.             <artifactId>webdrivermanager</artifactId>
  12.             <version>5.5.3</version>
  13.         </dependency>
  14.         <!--        屏幕截图-->
  15.         <dependency>
  16.             <groupId>commons-io</groupId>
  17.             <artifactId>commons-io</artifactId>
  18.             <version>2.6</version>
  19.         </dependency>
  20.     </dependencies>
复制代码
 我们创建 Utils 类,用于存放自动化代码中的通用方法:
  1. public class Utils {
  2.     public static WebDriver webDriver;
  3.     /**
  4.      * 创建 webDriver 并 访问指定 url
  5.      * @param url
  6.      */
  7.     public Utils(String url) {
  8.         if (null == webDriver) {
  9.             WebDriverManager.edgedriver().setup();
  10.             EdgeOptions options = new EdgeOptions();
  11.             // 允许访问所有连接
  12.             options.addArguments("--remote-allow-origins=*");
  13.             this.webDriver = new EdgeDriver(options);
  14.             // 隐式等待 3 秒
  15.             this.webDriver.manage().timeouts().implicitlyWait(java.time.Duration.ofSeconds(3));
  16.         }
  17.         webDriver.get(url);
  18.     }
  19.     /**
  20.      * 关闭 WebDriver 和浏览器
  21.      */
  22.     public void closeBrowser() {
  23.         if (webDriver != null) {
  24.             webDriver.quit();
  25.         }
  26.     }
  27.     /**
  28.      * 进行屏幕截图并将其保存到自定路径
  29.      * 路径: ./src/tests/image/2025-2-24/LoginPage-17548130.png
  30.      * @param str
  31.      */
  32.     public void getScreenShot(String str) {
  33.         try {
  34.             DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  35.             DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HHmmssSS");
  36.             String dirTime = dateFormatter.format(LocalDateTime.now());
  37.             String fileTime = timeFormatter.format(LocalDateTime.now());
  38.             // 使用 File.separator 来适应不同操作系统上的路径分隔符
  39.             String filename = "src" + File.separator + "test" + File.separator + "image" + File.separator + dirTime + File.separator + str + "-" + fileTime + ".png";
  40.             // 创建目录
  41.             Path path = Paths.get(filename).getParent();
  42.             if (path != null && !Files.exists(path)) {
  43.                 Files.createDirectories(path);
  44.             }
  45.             // 将截图存放到指定位置
  46.             File srcFile = ((TakesScreenshot)webDriver).getScreenshotAs(OutputType.FILE);
  47.             File destFile = new File(filename);
  48.             FileUtils.copyFile(srcFile, destFile);
  49.         } catch (IOException e) {
  50.             // 更好的错误处理或日志记录
  51.             System.err.println("截图失败: " + e.getMessage());
  52.             e.printStackTrace();
  53.         }
  54.     }
  55. }
复制代码
对职员列表页进行测试:
  1. public class UserListPage extends Utils {
  2.     private static String url = "http://49.108.48.236:8080/user-list.html";
  3.     public UserListPage() {
  4.         super(url);
  5.     }
  6.     /**
  7.      * 未登录状态下访问人员列表页
  8.      */
  9.     public void noLoginToUserListPage() {
  10.         // 处理弹窗
  11.         WebDriverWait wait = new WebDriverWait(webDriver, Duration.ofSeconds(5));
  12.         wait.until(ExpectedConditions.alertIsPresent());// 等待弹窗出现
  13.         Alert alert = webDriver.switchTo().alert();
  14.         alert.accept();
  15.         // 判断是否返回到登录页面
  16.         String expect = webDriver.getTitle();
  17.         assert expect.equals("管理员登录页面");
  18.     }
  19.     /**
  20.      * 检查人员列表页是否加载成功
  21.      */
  22.     public void userListPageRight() {
  23.         // 1. 进行登录
  24.         webDriver.findElement(By.cssSelector("#phoneNumber")).clear();
  25.         webDriver.findElement(By.cssSelector("#password")).clear();
  26.         webDriver.findElement(By.cssSelector("#phoneNumber")).sendKeys("13311111111");
  27.         webDriver.findElement(By.cssSelector("#password")).sendKeys("13311111111");
  28.         webDriver.findElement(By.cssSelector("#loginForm > button")).click();
  29.         // 2. 等待页面加载
  30.         WebDriverWait wait = new WebDriverWait(webDriver, Duration.ofSeconds(5));
  31.         wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#userList")));
  32.         // 3. 导航到人员列表页
  33.         webDriver.findElement(By.cssSelector("#userList")).click();
  34.         // 4. 查看列表元素
  35.         wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#userList")));
  36.         getScreenShot(getClass().getName());
  37.     }
  38. }
复制代码
 进行测试:
  1. public class RunTest {
  2.     public static void main(String[] args) {
  3.         UserListPage userListPage = new UserListPage();
  4.         userListPage.noLoginToUserListPage();
  5.         userListPage.userListPageRight();
  6.         userListPage.closeBrowser();
  7.     }
  8. }
复制代码
 测试通过;


性能测试

利用 JMeter 管理员暗码登录接口获取职员列表接口获取奖品列表接口 以及 获取活动列表接口 进行性能测试:

聚合报告:

结果分析: 
1. 全部接口的非常率为0%,且相应时间较为稳定,说明系统在当前并发场景下具有良好的稳定性和可靠性
2. 总体吞吐量到达361.4/sec,单个接口的吞吐量也都在90次/秒以上,表明系统在当前并发场景下具备较强的处置处罚本领

相应时间:

结果分析: 
1. 管理员暗码登录接口的相应时间颠簸较大,平均在75 ms左右
2. 获取职员列表、奖品列表和活动列表接口的相应时间相对稳定,平均在43 ms左右

 每秒处置处罚事务数:

结果分析:
1. 在测试过程中,每秒处置处罚事务数基本保持在90次左右,说明系统在当前并发情况下仍能保持较高的处置处罚本领
 2. 接近测试竣事时,TPS有显着下降趋势,这是由于线程数目逐渐淘汰导致的
活泼线程数:

结果分析:
1. 测试开始后,线程数目敏捷上升至20个,并在大部门时间内保持稳定
2. 接近测试竣事时,线程数目逐渐淘汰,终极降至0,表明全部线程任务完成并退出

总结

功能测试:
1. 在线抽奖系统的基本功能正常运行,正常流程可以或许正确实行
2. 用户进行抽奖时相应及时,可以或许对抽奖过程中的非常情况进行处置处罚
3. 在进行抽奖关照时,仅利用 qq 邮箱进行关照,可对其进行优化,使系统支持多种邮箱关照以及验证码关照

界面测试:
1. 全部按钮点击相应及时,页面显示良好,无错别字,无遮挡或显示错误情况
2. 对于非常情况都利用弹窗进行提示,对用户体验不友好,可利用自界说模态框、表单验证反馈等进行提示

性能测试:
1. 该系统的性能测试结果表明其在当前并发场景下表现良好,可以或许满意需求
2. 后续可调整测试设置,增加线程数或调整循环次数,以测试更高并发用户数下性能

其他改进点:
1. 客户端发送的手机号和暗码在网络中明文传输,应对其进行加密
2. 添加奖品信息修改删除功能以及职员信息修改删除功能
3. 限制单个用户的抽奖次数和频率,防止恶意刷奖

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

写过一篇

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表