-
Notifications
You must be signed in to change notification settings - Fork 287
Add use_test_helper()
#1978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add use_test_helper()
#1978
Conversation
…e is `tests/testthat/helper.R`
As per the discussion in #1822, let's strip this down to just creating/opening a test helper file. |
Should it be documented with |
It looks hard to document with |
Merge commit '1909b25e110f5a97b2d1c393d0218a2768078a46' #Conflicts: # NEWS.md
Merge commit '875aa503ae50d29e37293d85c98656a72cfbbd43' #Conflicts: # NEWS.md
Condition | ||
Error in `use_test_helper()`: | ||
x Your package must use testthat to use a helper file. | ||
Call `usethis::use_testthat()` to set up testthat. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a "todo" bullet, so I'm going to open a separate issue about that. Has nothing to do with this PR.
Thanks! |
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 nottests/testthat/helper.R
, but nottests/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.. 31d68a2