All Projects β†’ yihui β†’ testit

yihui / testit

Licence: other
A simple package for testing R packages

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to testit

opencage
🌐 R package for the OpenCage API -- both forward and reverse geocoding 🌐
Stars: ✭ 82 (+82.22%)
Mutual labels:  r-package
awspack
Amazon Web Services Bundle Package
Stars: ✭ 14 (-68.89%)
Mutual labels:  r-package
flipper
Make it easy to flip through R packages from CRAN, Bioconductor, and GitHub
Stars: ✭ 13 (-71.11%)
Mutual labels:  r-package
TDAstats
R pipeline for computing persistent homology in topological data analysis. See https://doi.org/10.21105/joss.00860 for more details.
Stars: ✭ 26 (-42.22%)
Mutual labels:  r-package
realtime
No description or website provided.
Stars: ✭ 15 (-66.67%)
Mutual labels:  r-package
phsmethods
An R package to standardise methods used in Public Health Scotland (https://public-health-scotland.github.io/phsmethods/)
Stars: ✭ 43 (-4.44%)
Mutual labels:  r-package
MAnorm2
MAnorm2 for Normalizing and Comparing ChIP-seq Samples
Stars: ✭ 15 (-66.67%)
Mutual labels:  r-package
LandR
Landscape Ecosystem Modelling in R
Stars: ✭ 14 (-68.89%)
Mutual labels:  r-package
ghql
GraphQL R client
Stars: ✭ 128 (+184.44%)
Mutual labels:  r-package
modeltime.gluonts
GluonTS Deep Learning with Modeltime
Stars: ✭ 31 (-31.11%)
Mutual labels:  r-package
colocr
An R package for conducting co-localization analysis. Edit
Stars: ✭ 22 (-51.11%)
Mutual labels:  r-package
mapr
Map species occurrence data
Stars: ✭ 34 (-24.44%)
Mutual labels:  r-package
inline
Inline C, C++ or Fortran functions in R
Stars: ✭ 33 (-26.67%)
Mutual labels:  r-package
rodev
β›” ARCHIVED β›” Helper for rOpenSci Package Developpers
Stars: ✭ 24 (-46.67%)
Mutual labels:  r-package
dashboard
A R package dashboard generator
Stars: ✭ 42 (-6.67%)
Mutual labels:  r-package
BAS
BAS R package https://merliseclyde.github.io/BAS/
Stars: ✭ 36 (-20%)
Mutual labels:  r-package
flyio
Input Output Files in R from Cloud or Local
Stars: ✭ 46 (+2.22%)
Mutual labels:  r-package
VOSONDash
R Shiny application for interactive analysis of networks created by vosonSML.
Stars: ✭ 44 (-2.22%)
Mutual labels:  r-package
geoknife
R tools for geo-web processing of gridded data via the Geo Data Portal. geoknife slices up gridded data according to overlap with irregular features, such as watersheds, lakes, points, etc.
Stars: ✭ 64 (+42.22%)
Mutual labels:  r-package
datastorr
Simple data versioning and distribution
Stars: ✭ 57 (+26.67%)
Mutual labels:  r-package

testit

R-CMD-check Codecov test coverage Downloads from the RStudio CRAN mirror

This package provides two simple functions (30 lines of code in total):

  • assert(fact, ...): think of it as message(fact) + stopifnot(...)

  • test_pkg(package): runs tests with all objects (exported or non-exported) in the package namespace directly available, so no need to use the triple-colon package:::name for non-exported objects

Why?

Because it is tedious to type these commands repeatedly in tests:

message('checking if these numbers are equal...')
stopifnot(all.equal(1, 1+1e-10), 10*.1 == 1)

message('checking if a non-exported function works...')
stopifnot(is.character(package:::utility_foo(x = 'abcd', y = 1:100)))

With the two simple functions above, we type six letters (assert) instead of sixteen (message + stopifnot), and assert is also a more intuitive function name for testing purposes (you assert a fact followed by evidence):

assert('These numbers are equal', {

  (all.equal(1, 1 + 1e-10))

  (10 * .1 == 1)

})

assert('A non-exported function works', {
  res = utility_foo(x = 'abcd', y = 1:100)
  (is.character(res))
})

assert('T is TRUE and F is FALSE by default, but can be changed', {
  (T == TRUE )
  (F == FALSE)

  T = FALSE
  (T == FALSE)
})

R CMD check

Put the tests under the directory pkg_name/tests/testit/ (where pkg_name is the root directory of your package), and write a test-all.R under pkg_name/tests/:

library(testit)
test_pkg('pkg_name')

That is all for R CMD check. For package development, it is recommended to use devtools. In particular, Ctrl/Cmd + Shift + L in RStudio makes all objects in a package visible to you, and you can run tests interactively.

Installation

Stable version on CRAN:

install.packages('testit')

Development version:

devtools::install_github('yihui/testit')

More

How about testthat? Well, this package is far less sophisticated than testthat. There is nothing fancy in this package. Please do consider testthat if your tests require more granularity. I myself do not use testthat because I'm too lazy to learn the new vocabulary (testthat::expect_xxx). For testit, I do not need to think if I should use expect_equal, expect_equivalent, or expect_identical; I just write test conditions in parentheses that are expected to return TRUE. That is the only single rule to remember.

There is no plan to add new features or reinvent anything in this package. It is an intentionally tiny package.

Xunzi

Although he did not really mean it, Xunzi said something that happens to apply well to unit testing:

不积跬ζ­₯οΌŒζ— δ»₯θ‡³εƒι‡ŒοΌ›δΈη§―ε°ζ΅οΌŒζ— δ»₯ζˆζ±Ÿζ΅·γ€‚

This package is free and open source software, licensed under GPL-3.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].