Search…
Testing
Testing in software development is a process that aims to evaluate the functionality of an application with an intent to find whether the code met the specified requirements or not as well as identifying the problems to ensure that the product has expected quality.

Automated tests

Automated tests follow the process of testing the software using an automation tool to find the defects. In this process, programmers execute the test scripts and generate the test results automatically by using automation tools.

Tests in V

In V, all test files have to be named with the following format: *_test.v and the functions should start with 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!
To execute the test, you should run v test_sum.v.

Examples

  1. 1.
    Testing JSON structures:
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.
    Testing files:
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!
Last modified 2yr ago