Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gagolews/realtest
When Expectations Meet Reality: Realistic Unit Testing in R
https://github.com/gagolews/realtest
continuous-testing r testing-tools unit-testing
Last synced: 3 months ago
JSON representation
When Expectations Meet Reality: Realistic Unit Testing in R
- Host: GitHub
- URL: https://github.com/gagolews/realtest
- Owner: gagolews
- License: other
- Created: 2021-05-26T23:17:10.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-07-11T10:22:41.000Z (7 months ago)
- Last Synced: 2024-11-16T22:39:59.867Z (3 months ago)
- Topics: continuous-testing, r, testing-tools, unit-testing
- Language: HTML
- Homepage: https://realtest.gagolewski.com
- Size: 13.6 MB
- Stars: 11
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: NEWS
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# [**`realtest`**](https://realtest.gagolewski.com)### Where Expectations Meet Reality: Realistic Unit Testing in [R](https://www.r-project.org/)
> [**`realtest`**](https://realtest.gagolewski.com/) is a framework for unit testing
> for realistic minimalists; it aids in formalising:
>
> * assertions,
> * current behaviour that we'd like to see changed in the future,
> * alternative yet perfectly acceptable practices (e.g., when outputs
> are platform-dependent and should remain so),
> * requested features to be implemented in due time
> (e.g., as part of the monitoring of third-party
> software projects for changes).The introduced vocabulary is (and will be kept!) minimalistic:
* **`P`** is *prototype* – you can use it to manually create a descriptor like
"*I expect this function to return `c(1, 2, 3)`, with a warning*"
or "*that should result in an error*";* **`R`** stands for *record* – creates a descriptor by evaluating an
expression and capturing its direct and indirect effects:* values generated (together with object attributes),
* errors,
* warnings and messages,
* text output on `stdout` and `stderr`;* **`E`** means *expect* – compares an expression under scrutiny (via `R`)
with a series of descriptors (created via `P` or `R` and using
a pairwise comparer provided) and stores the matching one (if any).--------------------------------------------------------------------------------
Some examples:
```r
library("realtest") # call install.packages("realtest") first# identical
E(sqrt(4), 2.0) # equivalent to E(sqrt(4), P(2.0))# almost-equal (round-off errors)
E(sin(pi), 0.0, value_comparer=all.equal)# two equally okay possible outcomes:
E(sample(c("head", "tail"), 1), "head", "tail")# not-a-number, with a warning
E(sqrt(-1), P(NaN, warning=TRUE))# desired vs. current vs. undesired (because it can always be worse!) behaviour
E(
paste0(1:2, 1:3), # expression to test - concatenation
best=P( # what we yearn for (ideally)
c("11", "22", "13"),
warning=TRUE
),
current=c("11", "22", "13"), # this is the behaviour we have now
bad=P(error=TRUE) # avoid regression
# and of course, everything else (un-expected) makes up a failed test
)
```Refer to the on-line documentation at
for more details.To learn more about R, check out Marek's open-access (free!) textbook
[*Deep R Programming*](https://deepr.gagolewski.com/).--------------------------------------------------------------------------------
**Package Maintainer and Author**:
[Marek Gagolewski](https://www.gagolewski.com/)**Homepage**:
**CRAN Entry**:
**License**:
**`realtest`** is distributed under the terms of the GNU General Public License,
either Version 2 or Version 3, see
[LICENSE](https://raw.githubusercontent.com/gagolews/realtest/master/LICENSE)**Changelog**: see
[NEWS](https://raw.githubusercontent.com/gagolews/realtest/master/NEWS)