Search…
V by Example
en
V por exemplos
V mit einem Beispiel
V dengan Contoh
通过例子学V语言
例子
section_3
section_1
section_4
文件
JSON操作
调试
数组函数
section_2
コード例で学ぶV言語
Changelog
Contributing
Documentation Style Guide
Powered By
GitBook
调试
软件开发中的测试是一个过程,其目的是评估应用程序的功能,以确定代码是否满足指定的要求,并确定问题,以确保产品具有预期的质量。
自动化测试
自动化测试遵循使用自动化工具测试软件以发现缺陷的过程。在这个过程中,程序员使用自动化工具执行测试脚本并自动生成测试结果。
V中的测试
在V中,所有的测试文件都必须使用以下格式命名:
*u test.V
并且函数应该以
test
开头。
1
// sum.v in subfolder sum
2
module sum
3
4
pub fn
sum
(
a
,
b
int
)
int
{
5
return
a
+
b
6
}
Copied!
1
// sum_test.v
2
import
sum
3
4
fn
test_sum
()
{
5
assert sum
.
sum
(
2
,
3
)
==
5
6
// assert sum.sum(2, 3) == 777 // => sum_test.v:6: FAILED assertion
7
}
Copied!
要执行测试,应执行
v test_sum.v
。
练习
1.
测试JSON结构:
1
import
json
2
3
fn
test_encode_customer
(){
4
customer
:=
Customer
{
first_name
:
"Vitor"
,
last_name
:
"Oliveira"
}
5
expected
:=
'
{
"first_name"
:
"Vitor"
,
"last_name"
:
"Oliveira"
}
'
6
7
encoded_json
:=
json
.
encode
(
customer
)
8
assert encoded_json
==
expected
9
}
Copied!
1.
测试文件:
1
import
os
2
3
fn
test_file_creation
()
{
4
file_name
:=
'
.
/
new_file
.
txt'
5
content
:=
'text'
6
7
os
.
write_file
(
file_name
,
content
)
8
assert content
.
len
==
os
.
file_size
(
file_name
)
9
10
os
.
rm
(
file_name
)
11
}
Copied!
Previous
JSON操作
Next
数组函数
Last modified
2yr ago
Copy link
Contents
自动化测试
V中的测试
练习