usethis icon indicating copy to clipboard operation
usethis copied to clipboard

Add `use_test_helper()`

Open olivroy opened this issue 3 months ago • 0 comments

Fix #1822

Probably better to merge #1990 first.

If merged, I will add some pointer in https://testthat.r-lib.org/articles/special-files.html#helper-files.

Considerations:

Test interactively: be able to jump the 3 files easily R/mocks.R, tests/testthat/test-mocks.R and tests/testthat/helper-mocks.R .

use_test_helper() # will go to specific associated helper file if exists or tests/testthat/helper.R otherwise

In usethis, I'd type the 3 functions successively starting with mocks.R to see that the 3 way workflow works as expected.

A case I have not considered:

if multiple tests/testthat/helper-{file}.R exist, but not tests/testthat/helper.R, but not tests/testthat/helper-foofy.R, it would probably be better to have it than what I currently implemented (tests/testthat/helper.R)

Harder to jump back to test files or R from tests/testthat/helper.R, will create a possibly unwanted file. I added a condition to prevent that.. https://github.com/r-lib/usethis/pull/1978/commits/31d68a2a2ffd610c106e425a8b377290f3848b23

olivroy avatar Apr 11 '24 15:04 olivroy