目次
测试用例
功能测试
界面测试
自动化测试
性能测试
总结
测试用例
功能测试
下面以 注册功能 测试为例进行展示:
正常注册:
以 姓名:王五 邮箱:1342111111@qq.com 手机号:13421111111 暗码:1342111111 为例进行注册:
点击注册:
输入姓名、邮箱、手机号和暗码,点击注册按钮后,页面会提示 "注册成功,去登录" ,正常注册情况下功能正常
非常注册:
非常注册重要从以下角度进行测试:
1. 用户名非常:用户名为空
2. 邮箱非常
a. 邮箱为空
b. 邮箱格式错误
c. 邮箱已存在
3. 手机号非常:
a. 手机号为空
b. 手机号格式错误
c. 手机号已存在
4. 暗码非常:
a. 暗码为空
b. 暗码长度格式错误
c. 暗码中包罗特殊字符
未填写完注册信息,直接点击注册:
页面会提示对应信息未输入
邮箱格式错误:
邮箱已存在:
手机号格式错误:
手机号已存在:
暗码过长(大于 12 位):
暗码过短(小于 6 位):
暗码中包罗特殊字符:
非常注册情况下,会提示对应的非常信息
通过测试,在注册页面并未发现 bug
界面测试
以 登录页面 测试为例进行展示:
登录页面图片、按钮以及输入框正常显示,提示信息正确,无错别字,无关键信息遮挡情况
暗码登录和验证码登录之间可以或许正确切换,验证码登录按钮、输入框正确显示
压缩情况下,图片不再显示,仅显示登录信息
注册链接正确显示,可以或许跳转到注册页面
自动化测试
以 职员列表 为例进行演示:
引入依赖:
- <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();
- }
- }
复制代码 测试通过;
性能测试
利用 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企服之家,中国第一个企服评测及商务社交产业平台。 |