当前位置:网站首页>How to read excel test data in Go language, easy to learn
How to read excel test data in Go language, easy to learn
2022-07-29 19:32:00 【Rejoice in the testing world】
The data in the test is often saved in Excel, especially the steps and input parameters of some use cases.The advantage of this is that no matter what tool you use, no matter what programming language you use, you can automate testing by reading data in a common format.
In automated testing, the most commonly used programming languages are Python and Java, but with the popularity of golang, more and more technical teams use go language for automated testing.
This article is about how to read test data in excel in go language.
Excelize is a library written in Go language for manipulating Excel documents. Now we use excel files in xlsx format, which can be manipulated through the excelize library.In addition to supporting data manipulation, Excelize can also design styles, action icons, pivot tables and slicers.
open excel
1. Open excel
The advantage of the Go language is that defer can be used to perform some post-operations, and defer can be called at the end of the function execution, so after opening excel, you can directly close the file through defer, and other operations can be written later, so as not to forgetClose the file.
Read sheet
2. Read sheet form
An Excel will contain multiple tables, so you must first select a table to read the content in it. I personally think csv is a more suitable form for storing use case data. Just open the file directly, no need to select againTable, and csv only focuses on data, the operation will be much faster.But now excel is still used more, so I will continue to focus on reading the data, and I will talk about the csv format next time.
rows, err := f.GetRows("Sheet1")if err != nil {log.Fatal("Failed to open the form")}
The table gets a nested Slice, and each row of data can be obtained through the for loop:
for _, row := range rows {log.Println(row)}
Next iteration
You can also get an iterable object, manually iterate once through Next, and take out the header data of the first row.All data of this row can be obtained through rows.Columns().
The next loop will get all the test data.
for rows.Next() {columns, err := rows.Columns()if err != nil {log.Fatal("Error getting data")}log.Println(columns)}
Summary
The first step: read the file through OpenFile
Step 2: Read all row data through GetRows
You can also get the left and right rows through Rows, and then manually iterate to get the data through Next.
Finally: Available on the official account: Sad Spicy Tiao!Get a 216-page software test engineer interview collection document by yourself [free].And the corresponding video learning tutorials are shared for free!, including basic knowledge, Linux essentials, Shell, Internet program principles, Mysql database, packet capture tool topics, interface testing tools, advanced testing-Python programming, Web automated testing, APP automated testing, interface automated testing, testingAdvanced continuous integration, testing architecture development testing framework, performance testing, security testing, etc.
Now I invite you to join our software testing learning exchange group: [746506216
], note "join the group", everyone can join togetherDiscuss and communicate software testing, learn software testing techniques, interviews and other aspects of software testing together. There will also be free live classes to gain more testing skills. Let's advance Python automated testing/test development together and move towards a high-paying careerroad.
Friends who like software testing, if my blog is helpful to you, if you like my blog content, please "Like", "Comment" and "Favorite" with one click!
Self-study course for software test engineers:
Interface performance test—software testers must know 618 actual combat scene analysis
Meituan Interview Questions_Advanced Test 25K Job Interview - Software Testers Should See
Jmeter actual combat explanation case - software testers will definitely know
边栏推荐
- Neo4j开源NoSQL数据库
- Setting right:0 after sticky positioning does not take effect
- 算力顶天地,存力纳乾坤:国家超级计算济南中心的一体两面
- UG安装出现Server Start Failed. The Server May Already Be Running!!解决方法
- SK海力士工厂发生氢氟酸泄漏,3名工人受伤!官方称不会影响生产
- 手机银行体验性测试:如何获取用户真实感受
- 一次挖矿程序的清理(回忆版)
- 智能合约安全——重入漏洞
- 字节跳动基于 Iceberg 的海量特征存储实践
- 第02章 MySQL的数据目录【1.MySQL架构篇】【MySQL高级】
猜你喜欢
随机推荐
从零在AutoDL调试一份目标检测代码
500强企业研发效能提升课,今晚开课啦!
秋招之路-经典面试题之手写字符串函数
MarkBERT
R语言时间序列数据提取:使用xts包的last函数提取时间序列中最后面两周的数据(last 2 week)
swin-transformer初步理解
新博客
开放原子开源基金会为白金、黄金、白银捐赠人授牌,CSDN荣获黄金捐赠人
一线大厂软件测试面试题及答案解析,2022最强版...
NVIDIA首次推出Arm服务器CPU!黄仁勋:或在2022年完成对Arm收购
智能合约安全——重入漏洞
请问跑sql任务调度必须得设置依赖的上游节点嘛?比如说我sql里面a b两张表join出来的结果写入
MySQL 中的反斜杠 \\,真是太坑了
制作文件上传进度条
【7.23-7.29】博客精彩回顾
一次挖矿程序的清理(回忆版)
Apache Doris 1.1 特性揭秘:Flink 实时写入如何兼顾高吞吐和低延时
转载:同班毕业两夫妻退休待遇四比一
嵌入式开发:嵌入式基础——软件错误分类
Postgresql-xl全局快照代码走读与GTM原理(支线1)