Glossary entry (derived from question below)
English term or phrase:
test setup helpers
Russian translation:
вспомогательные функции настройки тестов/проверок
Added to glossary by
Andrew Tishin
Dec 31, 2022 12:50
1 yr ago
8 viewers *
English term
test setup helpers
English to Russian
Tech/Engineering
Computers: Software
Google Go
https://google.github.io/styleguide/go/best-practices
However, some situations require that the test not proceed. Calling t.Fatal is appropriate when some piece of test setup fails, especially in **test setup helpers**, without which you cannot run the rest of the test. In a table-driven test, t.Fatal is appropriate for failures that set up the whole test function before the test loop. Failures that affect a single entry in the test table, which make it impossible to continue with that entry, should be reported as follows:
If you’re not using t.Run subtests, use t.Error followed by a continue statement to move on to the next table entry.
If you’re using subtests (and you’re inside a call to t.Run), use t.Fatal, which ends the current subtest and allows your test case to progress to the next subtest.
Warning: It is not always safe to call t.Fatal and similar functions. More details here.
However, some situations require that the test not proceed. Calling t.Fatal is appropriate when some piece of test setup fails, especially in **test setup helpers**, without which you cannot run the rest of the test. In a table-driven test, t.Fatal is appropriate for failures that set up the whole test function before the test loop. Failures that affect a single entry in the test table, which make it impossible to continue with that entry, should be reported as follows:
If you’re not using t.Run subtests, use t.Error followed by a continue statement to move on to the next table entry.
If you’re using subtests (and you’re inside a call to t.Run), use t.Fatal, which ends the current subtest and allows your test case to progress to the next subtest.
Warning: It is not always safe to call t.Fatal and similar functions. More details here.
Proposed translations
(Russian)
3 +1 | вспомогательные функции настройки тестов/проверок | Mikhail Zavidin |
Proposed translations
+1
44 mins
Selected
вспомогательные функции настройки тестов/проверок
First a quick review of the mechanics. When we run go test the go tool generates a main program that runs the test functions for our package. If the go tool finds a TestMain function it instead generates code to call TestMain. A typical TestMain follows.
func TestMain(m *testing.M) {
setup()
code := m.Run()
shutdown()
os.Exit(code)
}
From the above code we can see that writing a TestMain function allows us to control four aspects of test execution.
Setup.
How and when to run the tests.
Shutdown.
Exit behavior.
With appropriate use of these four items, we can satisfy several different use cases that were not well served prior to Go 1.4.
http://cs-guy.com/blog/2015/01/test-main/
--------------------------------------------------
Note added at 46 mins (2022-12-31 13:36:46 GMT)
--------------------------------------------------
Note that I provide argument tb to the setup and teardown functions, in case if we need something from the testing library. So you can leave the function alone without any argument if you want to. Now, if you run the test by running command go test -v, you’ll have something similar with this result printed on your terminal.
https://medium.com/nerd-for-tech/setup-and-teardown-unit-tes...
func TestMain(m *testing.M) {
setup()
code := m.Run()
shutdown()
os.Exit(code)
}
From the above code we can see that writing a TestMain function allows us to control four aspects of test execution.
Setup.
How and when to run the tests.
Shutdown.
Exit behavior.
With appropriate use of these four items, we can satisfy several different use cases that were not well served prior to Go 1.4.
http://cs-guy.com/blog/2015/01/test-main/
--------------------------------------------------
Note added at 46 mins (2022-12-31 13:36:46 GMT)
--------------------------------------------------
Note that I provide argument tb to the setup and teardown functions, in case if we need something from the testing library. So you can leave the function alone without any argument if you want to. Now, if you run the test by running command go test -v, you’ll have something similar with this result printed on your terminal.
https://medium.com/nerd-for-tech/setup-and-teardown-unit-tes...
4 KudoZ points awarded for this answer.
Comment: "Спасибо"
Something went wrong...