Testthat: "global" variable which can be used for all tests

Created on 23 Mar 2016  路  4Comments  路  Source: r-lib/testthat

Is there a way to assign a global variable in the beginning of the test? Thus, all testthat could use it. Or would that be against the policy that each testthat creates its own (clean) environment?
Thanks for the information.

Most helpful comment

You can create these in the "helper" files (R scripts that live in tests/testthat, name starts with "helper-"). These are executed once for each test run.

All 4 comments

You can create these in the "helper" files (R scripts that live in tests/testthat, name starts with "helper-"). These are executed once for each test run.

Cool, works already. Thanks a lot!

There's very little documentation on helpers in the testthat 1.0.2 docs -- are they covered somewhere else perhaps?

It's documented in http://testthat.r-lib.org/reference/test_dir.html#test-files or ?test_dir, but an introductory vignette would be very helpful.

Was this page helpful?
0 / 5 - 0 ratings