{"id":14069075,"url":"https://github.com/yihui/testit","last_synced_at":"2025-04-06T04:15:10.680Z","repository":{"id":9159283,"uuid":"10954856","full_name":"yihui/testit","owner":"yihui","description":"A simple package for testing R packages","archived":false,"fork":false,"pushed_at":"2024-06-26T20:45:26.000Z","size":111,"stargazers_count":58,"open_issues_count":1,"forks_count":12,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-30T03:06:13.461Z","etag":null,"topics":["r","r-package","testing"],"latest_commit_sha":null,"homepage":"https://cran.rstudio.com/package=testit","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yihui.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-06-26T01:13:14.000Z","updated_at":"2024-12-06T10:36:27.000Z","dependencies_parsed_at":"2022-09-06T02:31:04.047Z","dependency_job_id":"543c8bf6-0599-4286-b52e-8c8918edc6ef","html_url":"https://github.com/yihui/testit","commit_stats":{"total_commits":161,"total_committers":6,"mean_commits":"26.833333333333332","dds":0.06211180124223603,"last_synced_commit":"698afd467b040308e33179b69d87be0f8377d8ed"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yihui%2Ftestit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yihui%2Ftestit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yihui%2Ftestit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yihui%2Ftestit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yihui","download_url":"https://codeload.github.com/yihui/testit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247430963,"owners_count":20937875,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["r","r-package","testing"],"created_at":"2024-08-13T07:06:35.397Z","updated_at":"2025-04-06T04:15:10.458Z","avatar_url":"https://github.com/yihui.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"# testit\n\n\u003c!-- badges: start --\u003e\n\n[![R-CMD-check](https://github.com/yihui/testit/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/yihui/testit/actions/workflows/R-CMD-check.yaml)\n[![Codecov test\ncoverage](https://codecov.io/gh/yihui/testit/branch/master/graph/badge.svg)](https://codecov.io/gh/yihui/testit?branch=master)\n[![Downloads from the RStudio CRAN\nmirror](https://cranlogs.r-pkg.org/badges/testit)](https://cran.r-project.org/package=testit)\n\n\u003c!-- badges: end --\u003e\n\nThis package provides two simple functions (30 lines of code in total):\n\n-   `assert(fact, ...)`: think of it as `message(fact)` + `stopifnot(...)`\n\n-   `test_pkg(package)`: runs tests with all objects (exported or non-exported)\n    in the package namespace directly available, so no need to use the\n    triple-colon `package:::name` for non-exported objects\n\n## Why?\n\nBecause it is tedious to type these commands repeatedly in tests:\n\n``` r\nmessage('checking if these numbers are equal...')\nstopifnot(all.equal(1, 1+1e-10), 10*.1 == 1)\n\nmessage('checking if a non-exported function works...')\nstopifnot(is.character(package:::utility_foo(x = 'abcd', y = 1:100)))\n```\n\nWith the two simple functions above, we type six letters (`assert`) instead of\nsixteen (`message` + `stopifnot`), and `assert` is also a more intuitive\nfunction name for testing purposes (you *assert* a fact followed by evidence):\n\n``` r\nassert('These numbers are equal', {\n\n  (all.equal(1, 1 + 1e-10))\n\n  (10 * .1 == 1)\n\n})\n\nassert('A non-exported function works', {\n  res = utility_foo(x = 'abcd', y = 1:100)\n  (is.character(res))\n})\n\nassert('T is TRUE and F is FALSE by default, but can be changed', {\n  (T == TRUE )\n  (F == FALSE)\n\n  T = FALSE\n  (T == FALSE)\n})\n```\n\n## R CMD check\n\nPut the tests under the directory `pkg_name/tests/testit/` (where `pkg_name` is\nthe root directory of your package), and write a `test-all.R` under\n`pkg_name/tests/`:\n\n``` r\nlibrary(testit)\ntest_pkg('pkg_name')\n```\n\nThat is all for `R CMD check`. For package development, it is recommended to use\n[**devtools**](https://cran.r-project.org/package=devtools). In particular,\n`Ctrl/Cmd + Shift + L` in RStudio makes all objects in a package visible to you,\nand you can run tests interactively.\n\n## Installation\n\nStable version on CRAN:\n\n``` r\ninstall.packages('testit')\n```\n\nDevelopment version:\n\n``` r\nremotes::install_github('yihui/testit')\n```\n\n## More\n\nHow about [**testthat**](https://CRAN.R-project.org/package=testthat)? Well,\nthis package is far less sophisticated than **testthat**. There is nothing fancy\nin this package. Please do consider **testthat** if your tests require more\ngranularity. I myself do not use **testthat** because I'm too lazy to learn the\nnew vocabulary (`testthat::expect_xxx`). For **testit**, I do not need to think\nif I should use `expect_equal`, `expect_equivalent`, or `expect_identical`; I\njust write test conditions in parentheses that are expected to return `TRUE`.\nThat is the only single rule to remember.\n\nThere is no plan to add new features or reinvent anything in this package. It is\nan intentionally tiny package.\n\n\u003cimg src=\"https://i.imgur.com/sDsgmfj.jpg\" alt=\"Xunzi\" align=\"right\" width=\"100\"/\u003e\n\nAlthough he did not really mean it, [Xunzi](https://en.wikipedia.org/wiki/Xunzi)\nsaid something that happens to apply well to unit testing:\n\n\u003e 不积跬步，无以至千里；不积小流，无以成江海。\n\nThis package is free and open source software, licensed under GPL-3.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyihui%2Ftestit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyihui%2Ftestit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyihui%2Ftestit/lists"}