I’m developing a new package and I have some unit tests to write. What’s the difference between tests/ and inst/tests/? What kinds of stuff should go in each?
In particular, I see in http://journal.r-project.org/archive/2011-1/RJournal_2011-1_Wickham.pdf that Hadley recommends using inst/tests/ “so users
also have access to them,” then putting a reference in tests/ to run them all. But why not just put them all in tests/?
What @hadley means is that in binary packages,
tests/is not present; it is only in the source package. The convention is that anything ininst/is copied to the package top-level directory upon installation, soinst/tests/will be available as/testsin the binary and installed package directory structure.See my permute package as an example. I used @hadley’s testthat package as a learning experience and for my package tests. The package is on CRAN. Grab the source tarball and notice that it has both
tests/andinst/tests/, then grab the Windows binary and notice that only hastests/and that is a copy of the one frominst/testsin the sources.Strictly, only
tests/is run byR CMD checketc so during development and as checks in production packages you need code intests/to test the package does what it claims, or other unit tests. You can of course have code intests/that runs R scripts in/inst/tests/which actually do the tests, and this has the side effect of also making the test code available to package users.The way I see things is you need at least
tests/, whether you needinst/testswill depend upon how you want to develop your package and what unit testing code/packages you are using. Theinst/tests/is something @hadley advocates but it is far from being a standard across much of CRAN.