当前位置:网站首页>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

边栏推荐
猜你喜欢
随机推荐
C陷阱与缺陷
AI 通过了图灵测试,科学家反应冷淡:“很棒,但没必要”
leetcode:36. 有效的数独
500强企业如何提升研发效能?来看看行业专家怎么说
倒计时1天! | 明日9点,这场精彩的Web3盛宴不容错过
牛客网刷题记录 || 指针
白宫将举办半导体产业链CEO峰会,台积电、三星、格芯、英特尔等将参与
Neo4j开源NoSQL数据库
从零在AutoDL调试一份目标检测代码
小程序组件的总结
数字化来势汹汹,低代码起势,JNPF助力企业定制专属BIM
开放原子开源基金会为白金、黄金、白银捐赠人授牌,CSDN荣获黄金捐赠人
开放原子开源基金会秘书长孙文龙:要打造以开发者为本的开源服务平台
【7.23-7.29】博客精彩回顾
ECCV 2022 | AirDet:无需微调的小样本目标检测方法
StarRocks 2.3 新版本特性介绍
ARTS-第-25-期
制作文件上传进度条
The backslash \\ in MySQL is really a pit
实现get/post请求调用第三方接口









