You could do something like this
## Rmarkdown file with tests
```{r definefxn}
foo <- function(x) x^2
```
Test fxn
```{r testfxn}
library(testthat)
expect_is(foo(8), "numeric")
expect_equal(foo(8), 6)
```
Where of course the tests that pass don't print anything, but the tests that fail print meaningful messages about what failed.