@@ -9,13 +9,16 @@ and how they are woven into the standard Bioconductor build process.
99We hope that unit tests will become a standard part of your software
1010development, and an integral part of your Bioconductor package.
1111
12- We recommend either the [ RUnit] [ ] or [ testthat] [ ] packages from CRAN to write unit
13- tests. RUnit is an _ R_ implementation of the [ agile] [ ] software development
14- 'XUnit' tools (see also [ JUnit] [ ] , [ PyUnit] [ ] ) each of which tries to encourage, in
15- their respective language, the rapid development of robust useful
16- software. Testthat also draws inspiration from the xUnit family of testing
17- packages, as well as from many of the innovative ruby testing libraries, like
18- [ rspec] [ ] , [ testy] [ ] , [ bacon] [ ] and [ cucumber] [ ] .
12+ We recommend either the [ RUnit] [ ] , [ tinytest] [ ] , or [ testthat] [ ] packages from
13+ CRAN to write unit tests. ` RUnit ` is an _ R_ implementation of the [ agile] [ ]
14+ software development 'XUnit' tools (see also [ JUnit] [ ] , [ PyUnit] [ ] ) each of
15+ which tries to encourage, in their respective language, the rapid development of
16+ robust useful software. ` tinytest ` is a lightweight (zero-dependency) and
17+ easy-to-use unit testing framework. ` testthat ` also draws inspiration from the
18+ 'XUnit' family of testing packages, as well as from many of the innovative ruby
19+ testing libraries, like [ rspec] [ ] , [ testy] [ ] , [ bacon] [ ] and [ cucumber] [ ] .
20+
21+ [ tinytest ] : https://cran.r-project.org/package=tinytest
1922
2023## Motivation {#tests-motivation}
2124
@@ -44,18 +47,25 @@ formalized** unit testing. This requires only a very few conventions
4447and practices:
4548
4649* Store the test functions in a standard directory.
47- * Use simple functions from the * RUnit* or * testthat* packages to check your results.
50+ * Use simple functions from the * RUnit* , * tinytest* , or * testthat* packages to
51+ check your results.
4852* Run the tests as a routine part of your development process.
4953
50- Here is a RUnit test for ` divideBy ` :
54+ Here is a ` RUnit ` test for ` divideBy ` :
5155
5256 test_divideBy <- function() {
5357 checkEquals(divideBy(4, 2), 2)
5458 checkTrue(is.na(divideBy(4, 0)))
5559 checkEqualsNumeric(divideBy(4, 1.2345), 3.24, tolerance=1.0e-4)
5660 }
61+
62+ the equivalent test using ` tinytest ` :
63+
64+ expect_equal(divideBy(4, 2), 2)
65+ expect_true(is.na(divideBy(4, 0)))
66+ expect_equal(divideBy(4, 1.2345), 3.24, tolerance=1.0e-4)
5767
58- And the equivalent test suing testthat:
68+ and the equivalent test using ` testthat ` :
5969
6070 test_that("divideBy works properly", {
6171 expect_equal(divideBy(4, 2), 2)
@@ -110,9 +120,9 @@ complete set of tests.
110120
111121## Deciding Which Test Framework To Use {#which-tests}
112122
113- RUnit and testthat are both robust testing solutions that are great tools for
114- package development, which you choose to use for your package largely comes
115- down to personal preference. However here is a brief list of strengths and
123+ RUnit, tinytest, and testthat are robust testing solutions that are great tools
124+ for package development, which you choose to use for your package largely comes
125+ down to personal preference. However here is a brief list of strengths and
116126weaknesses of each.
117127
118128### RUnit Strengths ###
@@ -130,6 +140,16 @@ weaknesses of each.
130140- More difficult to setup and run natively (although see
131141 ` BiocGenerics:::testPackage() ` below which handles some of this).
132142
143+ ### tinytest Strengths ###
144+
145+ - Easy to setup and use; tests written as scripts
146+ - Tests can be run interactively as well as via ` R CMD check `
147+ - Test results can be treated as data
148+
149+ ### tinytest Weaknesses ###
150+
151+ - Minimally necessary functionality available
152+
133153### Testthat Strengths ###
134154
135155- Active development with over 39 contributors.
@@ -303,19 +323,31 @@ structure.
3033233 . You need to add ` Suggests: testthat ` to your ` DESCRIPTION ` file rather than
304324 ` Suggests: RUnit, BiocGenerics ` .
305325
326+ ### Conversion from RUnit to tinytest
327+
328+ 1 . Test files are placed in the ` inst/tinytest ` directory with names such as
329+ ` test_FILE.R ` .
330+ 2 . Remove ` RUnit ` function shells and extract the function bodies into a single
331+ script.
332+ 3 . Include a ` tinytest.R ` file in the ` tests ` folder that runs:
333+ ```
334+ if (requireNamespace("tinytest", quietly = TRUE))
335+ tinytest::test_package("PACKAGE")
336+ ```
337+ 3 . Add ` Suggests: testthat ` to your ` DESCRIPTION ` file.
338+
306339## Test Coverage {#test-coverage}
307340
308341[ Test coverage] ( https://en.wikipedia.org/wiki/Code_coverage )
309342refers to the percentage of your package code
310343that is tested by your unit tests. Packages with higher coverage
311344have a lower chance of containing bugs.
312345
313- If tests are taking too long to achieve full test coverage, see [ long
314- tests ] [ ] . Before implementing long tests we highly recommend reaching out to the
346+ If tests are taking too long to achieve full test coverage, see [ long tests ] [ ] .
347+ Before implementing long tests we highly recommend reaching out to the
315348bioconductor team on the [ bioc-devel] [ bioc-devel-mail ] mailing list to ensure
316349proper use and justification.
317350
318-
319351## Additional Resources
320352
321353Some web resources worth reading:
0 commit comments