testit

A simple package for testing R packages

https://github.com/yihui/testit

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.8%) to scientific vocabulary

Keywords

r r-package testing

Keywords from Contributors

data-manipulation grammar rmarkdown latex package-creation book geo bookdown epub gitbook
Last synced: 6 months ago · JSON representation

Repository

A simple package for testing R packages

Basic Info
Statistics
  • Stars: 58
  • Watchers: 6
  • Forks: 12
  • Open Issues: 1
  • Releases: 8
Topics
r r-package testing
Created over 12 years ago · Last pushed over 1 year ago
Metadata Files
Readme Changelog

README.md

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:

``` r 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):

``` r 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/:

r 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:

r install.packages('testit')

Development version:

r remotes::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.

Owner

  • Name: Yihui Xie
  • Login: yihui
  • Kind: user
  • Location: Omaha, NE
  • Company: @rstudio @swissre @merck

Freelancer (open source programmer, contractor, blogger, and writer)

GitHub Events

Total
Last Year

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 161
  • Total Committers: 6
  • Avg Commits per committer: 26.833
  • Development Distribution Score (DDS): 0.062
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Yihui Xie x****e@y****e 151
Christophe Dervieux c****x@g****m 6
Will Beasley w****y@h****m 1
Tomas Kalibera k****a 1
Steven M. Mortimer r****t@g****m 1
Jacob Long j****c@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 7
  • Total pull requests: 8
  • Average time to close issues: 21 days
  • Average time to close pull requests: 1 day
  • Total issue authors: 7
  • Total pull request authors: 5
  • Average comments per issue: 2.43
  • Average comments per pull request: 0.75
  • Merged pull requests: 8
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • cderv (1)
  • shrektan (1)
  • kadyb (1)
  • StevenMMortimer (1)
  • jayvdb (1)
  • leeper (1)
  • tomasruizt (1)
Pull Request Authors
  • cderv (4)
  • StevenMMortimer (1)
  • wibeasley (1)
  • jacob-long (1)
  • kalibera (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • cran 9,908 last-month
  • Total docker downloads: 4,688,740
  • Total dependent packages: 44
    (may contain duplicates)
  • Total dependent repositories: 235
    (may contain duplicates)
  • Total versions: 21
  • Total maintainers: 1
cran.r-project.org: testit

A Simple Package for Testing R Packages

  • Versions: 14
  • Dependent Packages: 44
  • Dependent Repositories: 234
  • Downloads: 9,908 Last month
  • Docker Downloads: 4,688,740
Rankings
Dependent repos count: 1.2%
Dependent packages count: 1.8%
Downloads: 4.5%
Forks count: 5.5%
Average: 6.2%
Stargazers count: 6.4%
Docker downloads count: 17.7%
Maintainers (1)
Last synced: 7 months ago
conda-forge.org: r-testit
  • Versions: 7
  • Dependent Packages: 0
  • Dependent Repositories: 1
Rankings
Dependent repos count: 24.3%
Average: 39.4%
Stargazers count: 39.7%
Forks count: 41.8%
Dependent packages count: 51.6%
Last synced: 6 months ago

Dependencies

DESCRIPTION cran
  • covr * suggests
  • rstudioapi * suggests